aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/ADT/StringMap.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-04-04 00:29:37 +0000
committerChris Lattner <sabre@nondot.org>2007-04-04 00:29:37 +0000
commit794a014809d810b7ee9a96be76774185561f0dcc (patch)
tree06a20070c173a93c88671f57850e5549bd9afdfb /include/llvm/ADT/StringMap.h
parent755e98bf6387ebe6e26705711f6fb9b25dd33119 (diff)
downloadexternal_llvm-794a014809d810b7ee9a96be76774185561f0dcc.tar.gz
external_llvm-794a014809d810b7ee9a96be76774185561f0dcc.tar.bz2
external_llvm-794a014809d810b7ee9a96be76774185561f0dcc.zip
Extend StringMap to support being initialized as completely empty. When
initialized this way, they do not do a malloc to allocate their buckets. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35642 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/StringMap.h')
-rw-r--r--include/llvm/ADT/StringMap.h35
1 files changed, 24 insertions, 11 deletions
diff --git a/include/llvm/ADT/StringMap.h b/include/llvm/ADT/StringMap.h
index c035f8cc6d..3c5f76a3c1 100644
--- a/include/llvm/ADT/StringMap.h
+++ b/include/llvm/ADT/StringMap.h
@@ -55,6 +55,7 @@ protected:
unsigned NumTombstones;
unsigned ItemSize;
protected:
+ StringMapImpl(unsigned itemSize) : ItemSize(itemSize) { init(16); }
StringMapImpl(unsigned InitSize, unsigned ItemSize);
void RehashTable();
@@ -87,7 +88,8 @@ protected:
/// RemoveKey - Remove the StringMapEntry for the specified key from the
/// table, returning it. If the key is not in the table, this returns null.
StringMapEntryBase *RemoveKey(const char *KeyStart, const char *KeyEnd);
-
+private:
+ void init(unsigned Size);
public:
static StringMapEntryBase *getTombstoneVal() {
return (StringMapEntryBase*)-1;
@@ -185,7 +187,8 @@ class StringMap : public StringMapImpl {
AllocatorTy Allocator;
typedef StringMapEntry<ValueTy> MapEntryTy;
public:
- StringMap(unsigned InitialSize = 0)
+ StringMap() : StringMapImpl(sizeof(MapEntryTy)) {}
+ StringMap(unsigned InitialSize)
: StringMapImpl(InitialSize, sizeof(MapEntryTy)) {}
AllocatorTy &getAllocator() { return Allocator; }
@@ -194,11 +197,18 @@ public:
typedef StringMapConstIterator<ValueTy> const_iterator;
typedef StringMapIterator<ValueTy> iterator;
- iterator begin() { return iterator(TheTable); }
- iterator end() { return iterator(TheTable+NumBuckets); }
- const_iterator begin() const { return const_iterator(TheTable); }
- const_iterator end() const { return const_iterator(TheTable+NumBuckets); }
-
+ iterator begin() {
+ return iterator(TheTable, NumBuckets == 0);
+ }
+ iterator end() {
+ return iterator(TheTable+NumBuckets, true);
+ }
+ const_iterator begin() const {
+ return const_iterator(TheTable, NumBuckets == 0);
+ }
+ const_iterator end() const {
+ return const_iterator(TheTable+NumBuckets, true);
+ }
iterator find(const char *KeyStart, const char *KeyEnd) {
int Bucket = FindKey(KeyStart, KeyEnd);
@@ -279,8 +289,10 @@ class StringMapConstIterator {
protected:
StringMapImpl::ItemBucket *Ptr;
public:
- StringMapConstIterator(StringMapImpl::ItemBucket *Bucket) : Ptr(Bucket) {
- AdvancePastEmptyBuckets();
+ StringMapConstIterator(StringMapImpl::ItemBucket *Bucket,
+ bool NoAdvance = false)
+ : Ptr(Bucket) {
+ if (!NoAdvance) AdvancePastEmptyBuckets();
}
const StringMapEntry<ValueTy> &operator*() const {
@@ -316,8 +328,9 @@ private:
template<typename ValueTy>
class StringMapIterator : public StringMapConstIterator<ValueTy> {
public:
- StringMapIterator(StringMapImpl::ItemBucket *Bucket)
- : StringMapConstIterator<ValueTy>(Bucket) {
+ StringMapIterator(StringMapImpl::ItemBucket *Bucket,
+ bool NoAdvance = false)
+ : StringMapConstIterator<ValueTy>(Bucket, NoAdvance) {
}
StringMapEntry<ValueTy> &operator*() const {
return *static_cast<StringMapEntry<ValueTy>*>(this->Ptr->Item);