mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 02:52:53 +02:00
ADT: Use perfect forwarding in StringMapEntry::Create()
Now you can pass references into constructors. llvm-svn: 221946
This commit is contained in:
parent
97786a6d08
commit
4858dd34c9
@ -117,8 +117,9 @@ public:
|
|||||||
|
|
||||||
explicit StringMapEntry(unsigned strLen)
|
explicit StringMapEntry(unsigned strLen)
|
||||||
: StringMapEntryBase(strLen), second() {}
|
: StringMapEntryBase(strLen), second() {}
|
||||||
StringMapEntry(unsigned strLen, ValueTy V)
|
template <class InitTy>
|
||||||
: StringMapEntryBase(strLen), second(std::move(V)) {}
|
StringMapEntry(unsigned strLen, InitTy &&V)
|
||||||
|
: StringMapEntryBase(strLen), second(std::forward<InitTy>(V)) {}
|
||||||
|
|
||||||
StringRef getKey() const {
|
StringRef getKey() const {
|
||||||
return StringRef(getKeyData(), getKeyLength());
|
return StringRef(getKeyData(), getKeyLength());
|
||||||
@ -139,9 +140,8 @@ public:
|
|||||||
/// Create - Create a StringMapEntry for the specified key and default
|
/// Create - Create a StringMapEntry for the specified key and default
|
||||||
/// construct the value.
|
/// construct the value.
|
||||||
template <typename AllocatorTy, typename InitType>
|
template <typename AllocatorTy, typename InitType>
|
||||||
static StringMapEntry *Create(StringRef Key,
|
static StringMapEntry *Create(StringRef Key, AllocatorTy &Allocator,
|
||||||
AllocatorTy &Allocator,
|
InitType &&InitVal) {
|
||||||
InitType InitVal) {
|
|
||||||
unsigned KeyLength = Key.size();
|
unsigned KeyLength = Key.size();
|
||||||
|
|
||||||
// Allocate a new item with space for the string at the end and a null
|
// Allocate a new item with space for the string at the end and a null
|
||||||
@ -154,7 +154,7 @@ public:
|
|||||||
static_cast<StringMapEntry*>(Allocator.Allocate(AllocSize,Alignment));
|
static_cast<StringMapEntry*>(Allocator.Allocate(AllocSize,Alignment));
|
||||||
|
|
||||||
// Default construct the value.
|
// Default construct the value.
|
||||||
new (NewItem) StringMapEntry(KeyLength, std::move(InitVal));
|
new (NewItem) StringMapEntry(KeyLength, std::forward<InitType>(InitVal));
|
||||||
|
|
||||||
// Copy the string information.
|
// Copy the string information.
|
||||||
char *StrBuffer = const_cast<char*>(NewItem->getKeyData());
|
char *StrBuffer = const_cast<char*>(NewItem->getKeyData());
|
||||||
|
Loading…
Reference in New Issue
Block a user