[lld] r200956 - [mach-o] use new way to copy StringRefs
Nick Kledzik
kledzik at apple.com
Thu Feb 6 15:48:52 PST 2014
Author: kledzik
Date: Thu Feb 6 17:48:52 2014
New Revision: 200956
URL: http://llvm.org/viewvc/llvm-project?rev=200956&view=rev
Log:
[mach-o] use new way to copy StringRefs
Modified:
lld/trunk/lib/ReaderWriter/MachO/File.h
Modified: lld/trunk/lib/ReaderWriter/MachO/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/File.h?rev=200956&r1=200955&r2=200956&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/File.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/File.h Thu Feb 6 17:48:52 2014
@@ -25,12 +25,8 @@ public:
Atom::Scope scope, bool copyRefs) {
if (copyRefs) {
// Make a copy of the atom's name and content that is owned by this file.
- char *s = _allocator.Allocate<char>(name.size());
- memcpy(s, name.data(), name.size());
- name = StringRef(s, name.size());
- uint8_t *bytes = _allocator.Allocate<uint8_t>(content.size());
- memcpy(bytes, content.data(), content.size());
- content = llvm::makeArrayRef(bytes, content.size());
+ name = name.copy(_allocator);
+ content = content.copy(_allocator);
}
MachODefinedAtom *atom =
new (_allocator) MachODefinedAtom(*this, name, content, scope);
@@ -39,10 +35,8 @@ public:
void addUndefinedAtom(StringRef name, bool copyRefs) {
if (copyRefs) {
- // Make a copy of the atom's name and content that is owned by this file.
- char *s = _allocator.Allocate<char>(name.size());
- memcpy(s, name.data(), name.size());
- name = StringRef(s, name.size());
+ // Make a copy of the atom's name that is owned by this file.
+ name = name.copy(_allocator);
}
SimpleUndefinedAtom *atom =
new (_allocator) SimpleUndefinedAtom(*this, name);
More information about the llvm-commits
mailing list