[PATCH] D14690: Don't force std::set for SmallSet

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 16 14:54:29 PST 2015


> On 2015-Nov-16, at 14:41, Rafael EspĂ­ndola <rafael.espindola at gmail.com> wrote:
> 
>>> -template <typename T, unsigned N,  typename C = std::less<T> >
>>> +template <typename T, unsigned N, typename BigSet = DenseSet<T>>
>>> class SmallSet {
>>>   /// Use a SmallVector to hold the elements here (even though it will never
>>>   /// reach its 'large' stage) to avoid calling the default ctors of elements
>>>   /// we will never use.
>>>   SmallVector<T, N> Vector;
>>> -  std::set<T, C> Set;
>>> +  BigSet Set;
>> 
>> Does `sizeof(SmallSet<T, 1>)` change with this?
> 
> Probably depends on the standard library. With libstdc++ 5.1 and T == int I get
> 
> master: 80
> patch: 64

I just counted (manually) with libc++ and it looks like 5 pointers
down to 3 pointers, so also 16B savings.

However, `DenseSet` does immediately call malloc for 256B at
construction time (forgot this until I looked at the code).  So
you're not actually getting the benefit of small storage.

I think for this to make sense you'd want to use a
`SmallDenseSet<T, 1>`.  SmallDenseSet doesn't exist yet though.


More information about the llvm-commits mailing list