<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jan 11, 2014, at 9:11 PM, Sean Silva wrote:</div><blockquote type="cite"><div dir="ltr"><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">+    char* s = _storage.Allocate<char>(str.</span><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">size());</span><br>
<div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">LLD uses * on the right, correct?</span></div></div></blockquote><div>Fixed in 199074.</div><div><br></div><div>-Nick</div><div><br></div><blockquote type="cite"><div class="gmail_extra"><font class="Apple-style-span" color="#000000"><br></font><div class="gmail_quote">On Fri, Jan 10, 2014 at 8:11 PM, Nick Kledzik <span dir="ltr"><<a href="mailto:kledzik@apple.com" target="_blank">kledzik@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: kledzik<br>
Date: Fri Jan 10 19:11:49 2014<br>
New Revision: 198987<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=198987&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=198987&view=rev</a><br>
Log:<br>
[yaml] use BumpPtrAllocator for string copies<br>
<br>
Modified:<br>
    lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=198987&r1=198986&r2=198987&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=198987&r1=198986&r2=198987&view=diff</a><br>

==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Fri Jan 10 19:11:49 2014<br>
@@ -150,24 +150,19 @@ private:<br>
   typedef llvm::StringMap<const lld::Atom *> NameToAtom;<br>
   typedef llvm::DenseMap<const lld::Atom *, std::string> AtomToRefName;<br>
<br>
-  // Allocate a new copy of this string and keep track of allocations<br>
-  // in _stringCopies, so they can be freed when RefNameBuilder is destroyed.<br>
+  // Allocate a new copy of this string in _storage, so the strings<br>
+  // can be freed when RefNameBuilder is destroyed.<br>
   StringRef copyString(StringRef str) {<br>
-    // We want _stringCopies to own the string memory so it is deallocated<br>
-    // when the File object is destroyed.  But we need a StringRef that<br>
-    // points into that memory.<br>
-    std::unique_ptr<char[]> s(new char[str.size()]);<br>
-    memcpy(s.get(), str.data(), str.size());<br>
-    StringRef r = StringRef(s.get(), str.size());<br>
-    _stringCopies.push_back(std::move(s));<br>
-    return r;<br>
+    char* s = _storage.Allocate<char>(str.size());<br>
+    memcpy(s, str.data(), str.size());<br>
+    return StringRef(s, str.size());<br>
   }<br>
<br>
   unsigned int                         _collisionCount;<br>
   unsigned int                         _unnamedCounter;<br>
   NameToAtom                           _nameMap;<br>
   AtomToRefName                        _refNames;<br>
-  std::vector<std::unique_ptr<char[]>> _stringCopies;<br>
+  llvm::BumpPtrAllocator               _storage;<br>
 };<br>
<br>
 /// Used when reading yaml files to find the target of a reference<br>
@@ -640,17 +635,12 @@ template <> struct MappingTraits<const l<br>
       return _absoluteAtoms;<br>
     }<br>
<br>
-    // Allocate a new copy of this string and keep track of allocations<br>
-    // in _stringCopies, so they can be freed when File is destroyed.<br>
+    // Allocate a new copy of this string in _storage, so the strings<br>
+    // can be freed when File is destroyed.<br>
     StringRef copyString(StringRef str) {<br>
-      // We want _stringCopies to own the string memory so it is deallocated<br>
-      // when the File object is destroyed.  But we need a StringRef that<br>
-      // points into that memory.<br>
-      std::unique_ptr<char[]> s(new char[str.size()]);<br>
-      memcpy(s.get(), str.data(), str.size());<br>
-      StringRef r = StringRef(s.get(), str.size());<br>
-      _stringCopies.push_back(std::move(s));<br>
-      return r;<br>
+      char* s = _storage.Allocate<char>(str.size());<br>
+      memcpy(s, str.data(), str.size());<br>
+      return StringRef(s, str.size());<br>
     }<br>
<br>
     IO                                  &_io;<br>
@@ -660,7 +650,7 @@ template <> struct MappingTraits<const l<br>
     AtomList<lld::UndefinedAtom>         _undefinedAtoms;<br>
     AtomList<lld::SharedLibraryAtom>     _sharedLibraryAtoms;<br>
     AtomList<lld::AbsoluteAtom>          _absoluteAtoms;<br>
-    std::vector<std::unique_ptr<char[]>> _stringCopies;<br>
+    llvm::BumpPtrAllocator               _storage;<br>
   };<br>
<br>
   static void mapping(IO &io, const lld::File *&file) {<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>
</blockquote></div><br></body></html>