<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 13, 2015 at 10:47 AM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ruiu<br>
Date: Tue Jan 13 12:47:25 2015<br>
New Revision: 225814<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=225814&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=225814&view=rev</a><br>
Log:<br>
Replace vector<unique_ptr<File> with unique_ptr<File>.<br>
<br>
Because each InputElement has exactly one File, we no longer have<br>
to use a vector to store pointers to Files.<br>
<br>
Modified:<br>
    lld/trunk/include/lld/Core/InputGraph.h<br>
    lld/trunk/include/lld/Driver/WrapperInputGraph.h<br>
    lld/trunk/lib/Core/InputGraph.cpp<br>
    lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp<br>
<br>
Modified: lld/trunk/include/lld/Core/InputGraph.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/InputGraph.h?rev=225814&r1=225813&r2=225814&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/InputGraph.h?rev=225814&r1=225813&r2=225814&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/include/lld/Core/InputGraph.h (original)<br>
+++ lld/trunk/include/lld/Core/InputGraph.h Tue Jan 13 12:47:25 2015<br>
@@ -148,7 +148,7 @@ private:<br>
 class FileNode : public InputElement {<br>
 public:<br>
   FileNode(StringRef path)<br>
-      : InputElement(InputElement::Kind::File), _path(path), _nextFileIndex(0) {<br>
+      : InputElement(InputElement::Kind::File), _path(path), _done(false) {<br>
   }<br>
<br>
   virtual ErrorOr<StringRef> getPath(const LinkingContext &) const {<br>
@@ -169,35 +169,33 @@ public:<br>
   }<br>
<br>
   /// \brief Get the list of files<br>
-  range<InputGraph::FileIterT> files() {<br>
-    return make_range(_files.begin(), _files.end());<br>
-  }<br>
+  File *getFile() { return _file.get(); }<br>
<br>
   /// \brief add a file to the list of files<br>
   virtual void addFiles(InputGraph::FileVectorT files) {<br>
     assert(files.size() == 1);<br>
-    assert(_files.empty());<br>
-    for (std::unique_ptr<File> &ai : files)<br>
-      _files.push_back(std::move(ai));<br>
+    assert(!_file);<br>
+    _file.swap(files[0]);</blockquote><div> </div><div>_file = std::move(files[0]);<br><br>perhaps?<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   }<br>
<br>
   /// \brief Return the next File thats part of this node to the<br>
   /// resolver.<br>
   File *getNextFile() override {<br>
-    assert(_files.size() == 1);<br>
-    if (_nextFileIndex == _files.size())<br>
+    assert(_file);<br>
+    if (_done)<br>
       return nullptr;<br>
-    return _files[_nextFileIndex++].get();<br>
+    _done = true;<br>
+    return _file.get();<br>
   }<br>
<br>
   std::error_code parse(const LinkingContext &, raw_ostream &) override;<br>
<br>
 protected:<br>
   StringRef _path;                       // The path of the Input file<br>
-  InputGraph::FileVectorT _files;        // A vector of lld File objects<br>
+  std::unique_ptr<File> _file;        // A vector of lld File objects<br>
<br>
   // The next file that would be processed by the resolver<br>
-  uint32_t _nextFileIndex;<br>
+  bool _done;<br>
 };<br>
<br>
 /// \brief Represents Internal Input files<br>
@@ -206,14 +204,14 @@ public:<br>
   SimpleFileNode(StringRef path) : FileNode(path) {}<br>
   SimpleFileNode(StringRef path, std::unique_ptr<File> f)<br>
       : FileNode(path) {<br>
-    _files.push_back(std::move(f));<br>
+    _file.swap(f);<br></blockquote><div><br>Use the init list?<br><br>: FileNode(path), _file(std::move(f)) {<br>}<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   }<br>
<br>
   virtual ~SimpleFileNode() {}<br>
<br>
   /// \brief add a file to the list of files<br>
   virtual void appendInputFile(std::unique_ptr<File> f) {<br>
-    _files.push_back(std::move(f));<br>
+    _file.swap(f);<br></blockquote><div><br>_file = std::move(f);<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   }<br>
 };<br>
<br>
<br>
Modified: lld/trunk/include/lld/Driver/WrapperInputGraph.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/WrapperInputGraph.h?rev=225814&r1=225813&r2=225814&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/WrapperInputGraph.h?rev=225814&r1=225813&r2=225814&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/include/lld/Driver/WrapperInputGraph.h (original)<br>
+++ lld/trunk/include/lld/Driver/WrapperInputGraph.h Tue Jan 13 12:47:25 2015<br>
@@ -22,7 +22,7 @@ namespace lld {<br>
 class WrapperNode : public FileNode {<br>
 public:<br>
   WrapperNode(std::unique_ptr<File> file) : FileNode(file->path()) {<br>
-    _files.push_back(std::move(file));<br>
+    _file.swap(file);<br></blockquote><div><br>Init list again ?(oh, I guess FileNode would need a ctor taking the unique_ptr<File> for this case and the last - that might be a good thing?)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   }<br>
 };<br>
<br>
<br>
Modified: lld/trunk/lib/Core/InputGraph.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/InputGraph.cpp?rev=225814&r1=225813&r2=225814&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/InputGraph.cpp?rev=225814&r1=225813&r2=225814&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/Core/InputGraph.cpp (original)<br>
+++ lld/trunk/lib/Core/InputGraph.cpp Tue Jan 13 12:47:25 2015<br>
@@ -69,8 +69,8 @@ void InputGraph::skipGroup() {<br>
 }<br>
<br>
 std::error_code FileNode::parse(const LinkingContext &, raw_ostream &) {<br>
-  for (std::unique_ptr<File> &file : _files)<br>
-    if (std::error_code ec = file->parse())<br>
+  if (_file)<br>
+    if (std::error_code ec = _file->parse())<br>
       return ec;<br>
   return std::error_code();<br>
 }<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=225814&r1=225813&r2=225814&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=225814&r1=225813&r2=225814&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Tue Jan 13 12:47:25 2015<br>
@@ -928,9 +928,7 @@ bool MachOLinkingContext::customAtomOrde<br>
<br>
 static File *getFirstFile(const std::unique_ptr<InputElement> &elem) {<br>
   FileNode *e = dyn_cast<FileNode>(const_cast<InputElement *>(elem.get()));<br>
-  if (!e || e->files().empty())<br>
-    return nullptr;<br>
-  return e->files()[0].get();<br>
+  return e ? e->getFile() : nullptr;<br>
 }<br>
<br>
 static bool isLibrary(const std::unique_ptr<InputElement> &elem) {<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></div>