[LLVMdev] Some enhancements to ImmutableSet and FoldingSet
Nick Lewycky
nicholas at mxc.ca
Wed Feb 11 18:51:25 PST 2009
Bill Wendling wrote:
> On Wed, Feb 11, 2009 at 10:36 AM, Ben Laurie <benl at google.com> wrote:
>> I needed these for some work I'm doing in clang...
>>
> Yes sir! At least this message was informative. One thing:
>
> + int size() const {
> + int n = 0;
> + for(iterator i = begin() ; i != end() ; ++n, ++i)
> + ;
Please only call end() once. We use this pattern a lot in LLVM:
for (iterator i = begin(), e = end(); i != e; ++n, ++i)
;
But really I think you should just have:
return std::distance(begin(), end());
Nick
> + return n;
> + }
> + bool empty() const {
> + return size() == 0;
> + }
>
> empty() here isn't a constant-time method. Can you make it's time
> complexity O(1)?
>
> -bw
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
More information about the llvm-dev
mailing list