[llvm] r244044 - [YAMLTraits] Use StringRef::copy. No functionality change.
Benjamin Kramer
benny.kra at googlemail.com
Wed Aug 5 07:16:38 PDT 2015
Author: d0k
Date: Wed Aug 5 09:16:38 2015
New Revision: 244044
URL: http://llvm.org/viewvc/llvm-project?rev=244044&view=rev
Log:
[YAMLTraits] Use StringRef::copy. No functionality change.
Modified:
llvm/trunk/lib/Support/YAMLTraits.cpp
Modified: llvm/trunk/lib/Support/YAMLTraits.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/YAMLTraits.cpp?rev=244044&r1=244043&r2=244044&view=diff
==============================================================================
--- llvm/trunk/lib/Support/YAMLTraits.cpp (original)
+++ llvm/trunk/lib/Support/YAMLTraits.cpp Wed Aug 5 09:16:38 2015
@@ -332,17 +332,12 @@ std::unique_ptr<Input::HNode> Input::cre
StringRef KeyStr = SN->getValue(StringStorage);
if (!StringStorage.empty()) {
// Copy string to permanent storage
- unsigned Len = StringStorage.size();
- char *Buf = StringAllocator.Allocate<char>(Len);
- memcpy(Buf, &StringStorage[0], Len);
- KeyStr = StringRef(Buf, Len);
+ KeyStr = StringStorage.str().copy(StringAllocator);
}
return llvm::make_unique<ScalarHNode>(N, KeyStr);
} else if (BlockScalarNode *BSN = dyn_cast<BlockScalarNode>(N)) {
- StringRef Value = BSN->getValue();
- char *Buf = StringAllocator.Allocate<char>(Value.size());
- memcpy(Buf, Value.data(), Value.size());
- return llvm::make_unique<ScalarHNode>(N, StringRef(Buf, Value.size()));
+ StringRef ValueCopy = BSN->getValue().copy(StringAllocator);
+ return llvm::make_unique<ScalarHNode>(N, ValueCopy);
} else if (SequenceNode *SQ = dyn_cast<SequenceNode>(N)) {
auto SQHNode = llvm::make_unique<SequenceHNode>(N);
for (Node &SN : *SQ) {
@@ -365,10 +360,7 @@ std::unique_ptr<Input::HNode> Input::cre
StringRef KeyStr = KeyScalar->getValue(StringStorage);
if (!StringStorage.empty()) {
// Copy string to permanent storage
- unsigned Len = StringStorage.size();
- char *Buf = StringAllocator.Allocate<char>(Len);
- memcpy(Buf, &StringStorage[0], Len);
- KeyStr = StringRef(Buf, Len);
+ KeyStr = StringStorage.str().copy(StringAllocator);
}
auto ValueHNode = this->createHNodes(KVN.getValue());
if (EC)
More information about the llvm-commits
mailing list