summaryrefslogtreecommitdiff
path: root/include/llvm/ADT/StringMap.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/ADT/StringMap.h')
-rw-r--r--include/llvm/ADT/StringMap.h24
1 files changed, 10 insertions, 14 deletions
diff --git a/include/llvm/ADT/StringMap.h b/include/llvm/ADT/StringMap.h
index 6c2830b44914..a9f83d3f5091 100644
--- a/include/llvm/ADT/StringMap.h
+++ b/include/llvm/ADT/StringMap.h
@@ -37,12 +37,12 @@ template<typename ValueTy> class StringMapKeyIterator;
/// StringMapEntryBase - Shared base class of StringMapEntry instances.
class StringMapEntryBase {
- unsigned StrLen;
+ size_t StrLen;
public:
- explicit StringMapEntryBase(unsigned Len) : StrLen(Len) {}
+ explicit StringMapEntryBase(size_t Len) : StrLen(Len) {}
- unsigned getKeyLength() const { return StrLen; }
+ size_t getKeyLength() const { return StrLen; }
};
/// StringMapImpl - This is the base class of StringMap that is shared among
@@ -127,10 +127,10 @@ class StringMapEntry : public StringMapEntryBase {
public:
ValueTy second;
- explicit StringMapEntry(unsigned strLen)
+ explicit StringMapEntry(size_t strLen)
: StringMapEntryBase(strLen), second() {}
template <typename... InitTy>
- StringMapEntry(unsigned strLen, InitTy &&... InitVals)
+ StringMapEntry(size_t strLen, InitTy &&... InitVals)
: StringMapEntryBase(strLen), second(std::forward<InitTy>(InitVals)...) {}
StringMapEntry(StringMapEntry &E) = delete;
@@ -155,19 +155,16 @@ public:
template <typename AllocatorTy, typename... InitTy>
static StringMapEntry *Create(StringRef Key, AllocatorTy &Allocator,
InitTy &&... InitVals) {
- unsigned KeyLength = Key.size();
+ size_t KeyLength = Key.size();
// Allocate a new item with space for the string at the end and a null
// terminator.
- unsigned AllocSize = static_cast<unsigned>(sizeof(StringMapEntry))+
- KeyLength+1;
- unsigned Alignment = alignof(StringMapEntry);
+ size_t AllocSize = sizeof(StringMapEntry) + KeyLength + 1;
+ size_t Alignment = alignof(StringMapEntry);
StringMapEntry *NewItem =
static_cast<StringMapEntry*>(Allocator.Allocate(AllocSize,Alignment));
-
- if (NewItem == nullptr)
- report_bad_alloc_error("Allocation of StringMap entry failed.");
+ assert(NewItem && "Unhandled out-of-memory");
// Construct the value.
new (NewItem) StringMapEntry(KeyLength, std::forward<InitTy>(InitVals)...);
@@ -203,8 +200,7 @@ public:
template<typename AllocatorTy>
void Destroy(AllocatorTy &Allocator) {
// Free memory referenced by the item.
- unsigned AllocSize =
- static_cast<unsigned>(sizeof(StringMapEntry)) + getKeyLength() + 1;
+ size_t AllocSize = sizeof(StringMapEntry) + getKeyLength() + 1;
this->~StringMapEntry();
Allocator.Deallocate(static_cast<void *>(this), AllocSize);
}