[cfe-commits] r49570 - in /cfe/trunk/lib/Sema: IdentifierResolver.cpp IdentifierResolver.h
Argiris Kirtzidis
akyrtzi at gmail.com
Sat Apr 12 05:52:49 PDT 2008
Chris Lattner wrote:
>> + if (CurIndex == VECTOR_SIZE) {
>> + // Add a IdDeclInfo vector 'pool'
>> + IDIVecs.resize(IDIVecs.size() + 1);
>
> I believe this is O(n) on some std::list's. I'd just use
> IDIVecs.push_back(std::vector<t>()); This is guaranteed constant time
> and is more idiomatic.
Done.
>
>> + // Fill the vector
>> + IDIVecs.back().resize(VECTOR_SIZE);
>
> If you're using std::vector, why not just make this
> 'reserve(VECTOR_SIZE)' and then use push_back when adding elements.
> This way, the vector keeps track of the size, instead of having to
> maintain CurIndex in parallel?
>
>> }
>> + IdDeclInfo *IDI = &IDIVecs.back()[CurIndex];
>
> If you do that, this can just be push_back() + back().
I had tested both ways and found the 'resize and initialize all at once'
to be a tiny bit more efficient. This was on msvc though. I attached the
'reserve' way in case you'd like to test it yourself.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vec-reserve.patch
Type: text/x-diff
Size: 1448 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20080412/dfe5e2ac/attachment.patch>
More information about the cfe-commits
mailing list