[llvm-commits] [llvm] r147731 - /llvm/trunk/include/llvm/ADT/DenseMap.h
David Blaikie
dblaikie at gmail.com
Sat Jan 7 10:03:39 PST 2012
Great! I've been wondering about that for a few weeks now & wasn't sure
if you'd skipped that when you made the stringref fix because it wasn't
the same issue.
From: Benjamin Kramer
Sent: 1/7/2012 3:17 AM
To: llvm-commits at cs.uiuc.edu
Subject: [llvm-commits] [llvm] r147731
- /llvm/trunk/include/llvm/ADT/DenseMap.h
Author: d0k
Date: Sat Jan 7 07:12:07 2012
New Revision: 147731
URL: http://llvm.org/viewvc/llvm-project?rev=147731&view=rev
Log:
Port the trick to skip the check for empty buckets from StringMap to DenseMap.
This should fix the odd behavior that find() is slower than lookup().
Modified:
llvm/trunk/include/llvm/ADT/DenseMap.h
Modified: llvm/trunk/include/llvm/ADT/DenseMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/DenseMap.h?rev=147731&r1=147730&r2=147731&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/DenseMap.h (original)
+++ llvm/trunk/include/llvm/ADT/DenseMap.h Sat Jan 7 07:12:07 2012
@@ -86,13 +86,13 @@
return empty() ? end() : iterator(Buckets, Buckets+NumBuckets);
}
inline iterator end() {
- return iterator(Buckets+NumBuckets, Buckets+NumBuckets);
+ return iterator(Buckets+NumBuckets, Buckets+NumBuckets, true);
}
inline const_iterator begin() const {
return empty() ? end() : const_iterator(Buckets, Buckets+NumBuckets);
}
inline const_iterator end() const {
- return const_iterator(Buckets+NumBuckets, Buckets+NumBuckets);
+ return const_iterator(Buckets+NumBuckets, Buckets+NumBuckets, true);
}
bool empty() const { return NumEntries == 0; }
@@ -137,13 +137,13 @@
iterator find(const KeyT &Val) {
BucketT *TheBucket;
if (LookupBucketFor(Val, TheBucket))
- return iterator(TheBucket, Buckets+NumBuckets);
+ return iterator(TheBucket, Buckets+NumBuckets, true);
return end();
}
const_iterator find(const KeyT &Val) const {
BucketT *TheBucket;
if (LookupBucketFor(Val, TheBucket))
- return const_iterator(TheBucket, Buckets+NumBuckets);
+ return const_iterator(TheBucket, Buckets+NumBuckets, true);
return end();
}
@@ -162,13 +162,12 @@
std::pair<iterator, bool> insert(const std::pair<KeyT, ValueT> &KV) {
BucketT *TheBucket;
if (LookupBucketFor(KV.first, TheBucket))
- return std::make_pair(iterator(TheBucket, Buckets+NumBuckets),
+ return std::make_pair(iterator(TheBucket, Buckets+NumBuckets, true),
false); // Already in map.
// Otherwise, insert the new element.
TheBucket = InsertIntoBucket(KV.first, KV.second, TheBucket);
- return std::make_pair(iterator(TheBucket, Buckets+NumBuckets),
- true);
+ return std::make_pair(iterator(TheBucket, Buckets+NumBuckets, true), true);
}
/// insert - Range insertion of pairs.
@@ -495,8 +494,9 @@
public:
DenseMapIterator() : Ptr(0), End(0) {}
- DenseMapIterator(pointer Pos, pointer E) : Ptr(Pos), End(E) {
- AdvancePastEmptyBuckets();
+ DenseMapIterator(pointer Pos, pointer E, bool NoAdvance = false)
+ : Ptr(Pos), End(E) {
+ if (!NoAdvance) AdvancePastEmptyBuckets();
}
// If IsConst is true this is a converting constructor from iterator to
_______________________________________________
llvm-commits mailing list
llvm-commits at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list