[lld] r198987 - [yaml] use BumpPtrAllocator for string copies
Nick Kledzik
kledzik at apple.com
Sun Jan 12 20:13:44 PST 2014
On Jan 11, 2014, at 9:11 PM, Sean Silva wrote:
> + char* s = _storage.Allocate<char>(str.size());
>
> LLD uses * on the right, correct?
Fixed in 199074.
-Nick
>
> On Fri, Jan 10, 2014 at 8:11 PM, Nick Kledzik <kledzik at apple.com> wrote:
> Author: kledzik
> Date: Fri Jan 10 19:11:49 2014
> New Revision: 198987
>
> URL: http://llvm.org/viewvc/llvm-project?rev=198987&view=rev
> Log:
> [yaml] use BumpPtrAllocator for string copies
>
> Modified:
> lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
>
> Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=198987&r1=198986&r2=198987&view=diff
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)
> +++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Fri Jan 10 19:11:49 2014
> @@ -150,24 +150,19 @@ private:
> typedef llvm::StringMap<const lld::Atom *> NameToAtom;
> typedef llvm::DenseMap<const lld::Atom *, std::string> AtomToRefName;
>
> - // Allocate a new copy of this string and keep track of allocations
> - // in _stringCopies, so they can be freed when RefNameBuilder is destroyed.
> + // Allocate a new copy of this string in _storage, so the strings
> + // can be freed when RefNameBuilder is destroyed.
> StringRef copyString(StringRef str) {
> - // We want _stringCopies to own the string memory so it is deallocated
> - // when the File object is destroyed. But we need a StringRef that
> - // points into that memory.
> - std::unique_ptr<char[]> s(new char[str.size()]);
> - memcpy(s.get(), str.data(), str.size());
> - StringRef r = StringRef(s.get(), str.size());
> - _stringCopies.push_back(std::move(s));
> - return r;
> + char* s = _storage.Allocate<char>(str.size());
> + memcpy(s, str.data(), str.size());
> + return StringRef(s, str.size());
> }
>
> unsigned int _collisionCount;
> unsigned int _unnamedCounter;
> NameToAtom _nameMap;
> AtomToRefName _refNames;
> - std::vector<std::unique_ptr<char[]>> _stringCopies;
> + llvm::BumpPtrAllocator _storage;
> };
>
> /// Used when reading yaml files to find the target of a reference
> @@ -640,17 +635,12 @@ template <> struct MappingTraits<const l
> return _absoluteAtoms;
> }
>
> - // Allocate a new copy of this string and keep track of allocations
> - // in _stringCopies, so they can be freed when File is destroyed.
> + // Allocate a new copy of this string in _storage, so the strings
> + // can be freed when File is destroyed.
> StringRef copyString(StringRef str) {
> - // We want _stringCopies to own the string memory so it is deallocated
> - // when the File object is destroyed. But we need a StringRef that
> - // points into that memory.
> - std::unique_ptr<char[]> s(new char[str.size()]);
> - memcpy(s.get(), str.data(), str.size());
> - StringRef r = StringRef(s.get(), str.size());
> - _stringCopies.push_back(std::move(s));
> - return r;
> + char* s = _storage.Allocate<char>(str.size());
> + memcpy(s, str.data(), str.size());
> + return StringRef(s, str.size());
> }
>
> IO &_io;
> @@ -660,7 +650,7 @@ template <> struct MappingTraits<const l
> AtomList<lld::UndefinedAtom> _undefinedAtoms;
> AtomList<lld::SharedLibraryAtom> _sharedLibraryAtoms;
> AtomList<lld::AbsoluteAtom> _absoluteAtoms;
> - std::vector<std::unique_ptr<char[]>> _stringCopies;
> + llvm::BumpPtrAllocator _storage;
> };
>
> static void mapping(IO &io, const lld::File *&file) {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140112/641c0cef/attachment.html>
More information about the llvm-commits
mailing list