[llvm] r221946 - ADT: Use perfect forwarding in StringMapEntry::Create()

Duncan P. N. Exon Smith dexonsmith at apple.com
Thu Nov 13 16:17:08 PST 2014


The rvalue version is already used by in-tree code.

I'll be adding a use of the lvalue version in my next commit.

> On 2014-Nov-13, at 15:58, David Blaikie <dblaikie at gmail.com> wrote:
> 
> 
> 
> On Thu, Nov 13, 2014 at 3:23 PM, Duncan P. N. Exon Smith <dexonsmith at apple.com> wrote:
> Author: dexonsmith
> Date: Thu Nov 13 17:23:02 2014
> New Revision: 221946
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=221946&view=rev
> Log:
> ADT: Use perfect forwarding in StringMapEntry::Create()
> 
> Now you can pass references into constructors.
> 
> Unit test?
>  
> 
> 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=221946&r1=221945&r2=221946&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/ADT/StringMap.h (original)
> +++ llvm/trunk/include/llvm/ADT/StringMap.h Thu Nov 13 17:23:02 2014
> @@ -117,8 +117,9 @@ public:
> 
>    explicit StringMapEntry(unsigned strLen)
>      : StringMapEntryBase(strLen), second() {}
> -  StringMapEntry(unsigned strLen, ValueTy V)
> -      : StringMapEntryBase(strLen), second(std::move(V)) {}
> +  template <class InitTy>
> +  StringMapEntry(unsigned strLen, InitTy &&V)
> +      : StringMapEntryBase(strLen), second(std::forward<InitTy>(V)) {}
> 
>    StringRef getKey() const {
>      return StringRef(getKeyData(), getKeyLength());
> @@ -138,10 +139,9 @@ public:
> 
>    /// Create - Create a StringMapEntry for the specified key and default
>    /// construct the value.
> -  template<typename AllocatorTy, typename InitType>
> -  static StringMapEntry *Create(StringRef Key,
> -                                AllocatorTy &Allocator,
> -                                InitType InitVal) {
> +  template <typename AllocatorTy, typename InitType>
> +  static StringMapEntry *Create(StringRef Key, AllocatorTy &Allocator,
> +                                InitType &&InitVal) {
>      unsigned KeyLength = Key.size();
> 
>      // 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));
> 
>      // Default construct the value.
> -    new (NewItem) StringMapEntry(KeyLength, std::move(InitVal));
> +    new (NewItem) StringMapEntry(KeyLength, std::forward<InitType>(InitVal));
> 
>      // Copy the string information.
>      char *StrBuffer = const_cast<char*>(NewItem->getKeyData());
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 





More information about the llvm-commits mailing list