[PATCH] D16706: SmallSet/SmallPtrSet: Refuse huge SmallSize/N numbers
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 28 19:47:09 PST 2016
MatzeB created this revision.
MatzeB added reviewers: chandlerc, echristo, reames.
MatzeB added a subscriber: llvm-commits.
MatzeB set the repository for this revision to rL LLVM.
Herald added a subscriber: mcrosier.
These sets do linear searching in small mode; It is not a good idea to
use huge numbers as the small value here, save people from themselves by
adding a static_assert.
Repository:
rL LLVM
http://reviews.llvm.org/D16706
Files:
include/llvm/ADT/SmallPtrSet.h
include/llvm/ADT/SmallSet.h
Index: include/llvm/ADT/SmallSet.h
===================================================================
--- include/llvm/ADT/SmallSet.h
+++ include/llvm/ADT/SmallSet.h
@@ -38,6 +38,11 @@
typedef typename SmallVector<T, N>::const_iterator VIterator;
typedef typename SmallVector<T, N>::iterator mutable_iterator;
+ // In small mode SmallPtrSet uses linear search for the elements, so it is
+ // not a good idea to choose this value too high. You may consider using a
+ // DenseSet<> instead if you expect many elements in the set.
+ static_assert(N <= 32, "N should be small");
+
public:
typedef size_t size_type;
SmallSet() {}
Index: include/llvm/ADT/SmallPtrSet.h
===================================================================
--- include/llvm/ADT/SmallPtrSet.h
+++ include/llvm/ADT/SmallPtrSet.h
@@ -351,6 +351,11 @@
/// SmallPtrSetImplBase for details of the algorithm.
template<class PtrType, unsigned SmallSize>
class SmallPtrSet : public SmallPtrSetImpl<PtrType> {
+ // In small mode SmallPtrSet uses linear search for the elements, so it is
+ // not a good idea to choose this value too high. You may consider using a
+ // DenseSet<> instead if you expect many elements in the set.
+ static_assert(SmallSize <= 32, "SmallSize should be small");
+
typedef SmallPtrSetImpl<PtrType> BaseT;
// Make sure that SmallSize is a power of two, round up if not.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16706.46339.patch
Type: text/x-patch
Size: 1396 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160129/49f01e1b/attachment.bin>
More information about the llvm-commits
mailing list