static StringMapEntry *Create(const char *KeyStart, const char *KeyEnd,
AllocatorTy &Allocator,
InitType InitVal) {
- unsigned KeyLength = KeyEnd-KeyStart;
+ unsigned KeyLength = static_cast<unsigned>(KeyEnd-KeyStart);
// Okay, the item doesn't already exist, and 'Bucket' is the bucket to fill
// in. Allocate a new item with space for the string at the end and a null
// terminator.
- unsigned AllocSize = sizeof(StringMapEntry)+KeyLength+1;
+ unsigned AllocSize = static_cast<unsigned>(sizeof(StringMapEntry))+
+ KeyLength+1;
unsigned Alignment = alignof<StringMapEntry>();
StringMapEntry *NewItem =
AllocatorTy Allocator;
typedef StringMapEntry<ValueTy> MapEntryTy;
public:
- StringMap() : StringMapImpl(sizeof(MapEntryTy)) {}
+ StringMap() : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))) {}
explicit StringMap(unsigned InitialSize)
- : StringMapImpl(InitialSize, sizeof(MapEntryTy)) {}
+ : StringMapImpl(InitialSize, static_cast<unsigned>(sizeof(MapEntryTy))) {}
AllocatorTy &getAllocator() { return Allocator; }
const AllocatorTy &getAllocator() const { return Allocator; }
return find(Key, Key + strlen(Key));
}
iterator find(const std::string &Key) {
- const char* key_start = &Key[0];
+ const char* key_start = (Key.empty() ? NULL : &Key[0]);
return find(key_start, key_start + Key.size());
}
return find(Key, Key + strlen(Key));
}
const_iterator find(const std::string &Key) const {
- const char* key_start = &Key[0];
+ const char* key_start = (Key.empty() ? NULL : &Key[0]);
return find(key_start, key_start + Key.size());
}
return entry.getValue();
}
ValueTy& operator[](const std::string &Key) {
- const char* key_start = &Key[0];
+ const char* key_start = (Key.empty() ? NULL : &Key[0]);
value_type& entry = GetOrCreateValue(key_start, key_start + Key.size());
return entry.getValue();
}
return count(Key, Key + strlen(Key));
}
size_type count(const std::string &Key) const {
- const char* key_start = &Key[0];
+ const char* key_start = (Key.empty() ? NULL : &Key[0]);
return count(key_start, key_start + Key.size());
}
V.Destroy(Allocator);
}
+ bool erase(const char *Key) {
+ iterator I = find(Key);
+ if (I == end()) return false;
+ erase(I);
+ return true;
+ }
+
+ bool erase(std::string Key) {
+ iterator I = find(Key);
+ if (I == end()) return false;
+ erase(I);
+ return true;
+ }
+
~StringMap() {
for (ItemBucket *I = TheTable, *E = TheTable+NumBuckets; I != E; ++I) {
if (I->Item && I->Item != getTombstoneVal())