[llvm-commits] [llvm] r63707 - /llvm/trunk/include/llvm/ADT/StringMap.h
Chris Lattner
sabre at nondot.org
Tue Feb 3 17:54:10 PST 2009
Author: lattner
Date: Tue Feb 3 19:54:10 2009
New Revision: 63707
URL: http://llvm.org/viewvc/llvm-project?rev=63707&view=rev
Log:
fix a pretty serious bug in StringMap where GetOrCreate(strstart,strend, z)
would not set new values to Z.
Modified:
llvm/trunk/include/llvm/ADT/StringMap.h
Modified: llvm/trunk/include/llvm/ADT/StringMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringMap.h?rev=63707&r1=63706&r2=63707&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringMap.h (original)
+++ llvm/trunk/include/llvm/ADT/StringMap.h Tue Feb 3 19:54:10 2009
@@ -34,6 +34,7 @@
public:
template <typename InitTy>
static void Initialize(StringMapEntry<ValueTy> &T, InitTy InitVal) {
+ T.second = InitVal;
}
};
@@ -195,7 +196,7 @@
}
static StringMapEntry *Create(const char *KeyStart, const char *KeyEnd) {
- return Create(KeyStart, KeyEnd, 0);
+ return Create(KeyStart, KeyEnd, ValueTy());
}
/// GetStringMapEntryFromValue - Given a value that is known to be embedded
@@ -240,6 +241,17 @@
StringMap() : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))) {}
explicit StringMap(unsigned InitialSize)
: StringMapImpl(InitialSize, static_cast<unsigned>(sizeof(MapEntryTy))) {}
+ explicit StringMap(const StringMap &RHS)
+ : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))) {
+ assert(RHS.empty() &&
+ "Copy ctor from non-empty stringmap not implemented yet!");
+ }
+ void operator=(const StringMap &RHS) {
+ assert(RHS.empty() &&
+ "assignment from non-empty stringmap not implemented yet!");
+ clear();
+ }
+
AllocatorTy &getAllocator() { return Allocator; }
const AllocatorTy &getAllocator() const { return Allocator; }
@@ -292,13 +304,11 @@
}
ValueTy& operator[](const char *Key) {
- value_type& entry = GetOrCreateValue(Key, Key + strlen(Key));
- return entry.getValue();
+ return GetOrCreateValue(Key, Key + strlen(Key)).getValue();
}
ValueTy& operator[](const std::string &Key) {
const char* key_start = (Key.empty() ? NULL : &Key[0]);
- value_type& entry = GetOrCreateValue(key_start, key_start + Key.size());
- return entry.getValue();
+ return GetOrCreateValue(key_start, key_start + Key.size()).getValue();
}
size_type count(const char *KeyStart, const char *KeyEnd) const {
@@ -378,7 +388,7 @@
StringMapEntry<ValueTy> &GetOrCreateValue(const char *KeyStart,
const char *KeyEnd) {
- return GetOrCreateValue(KeyStart, KeyEnd, 0);
+ return GetOrCreateValue(KeyStart, KeyEnd, ValueTy());
}
/// remove - Remove the specified key/value pair from the map, but do not
@@ -411,9 +421,6 @@
clear();
free(TheTable);
}
-private:
- StringMap(const StringMap &); // FIXME: Implement.
- void operator=(const StringMap &); // FIXME: Implement.
};
More information about the llvm-commits
mailing list