Optimize empty DenseMap iteration.

llvm-svn: 103962
This commit is contained in:
Jakob Stoklund Olesen 2010-05-17 20:01:24 +00:00
parent 70563bbba5
commit 84a8415ed7
1 changed files with 3 additions and 2 deletions

View File

@ -79,13 +79,14 @@ public:
typedef DenseMapIterator<KeyT, ValueT,
KeyInfoT, ValueInfoT, true> const_iterator;
inline iterator begin() {
return iterator(Buckets, Buckets+NumBuckets);
// When the map is empty, avoid the overhead of AdvancePastEmptyBuckets().
return empty() ? end() : iterator(Buckets, Buckets+NumBuckets);
}
inline iterator end() {
return iterator(Buckets+NumBuckets, Buckets+NumBuckets);
}
inline const_iterator begin() const {
return const_iterator(Buckets, Buckets+NumBuckets);
return empty() ? end() : const_iterator(Buckets, Buckets+NumBuckets);
}
inline const_iterator end() const {
return const_iterator(Buckets+NumBuckets, Buckets+NumBuckets);