[lld] r225814 - Replace vector<unique_ptr<File> with unique_ptr<File>.

David Blaikie dblaikie at gmail.com
Tue Jan 13 10:58:08 PST 2015


On Tue, Jan 13, 2015 at 10:47 AM, Rui Ueyama <ruiu at google.com> wrote:

> Author: ruiu
> Date: Tue Jan 13 12:47:25 2015
> New Revision: 225814
>
> URL: http://llvm.org/viewvc/llvm-project?rev=225814&view=rev
> Log:
> Replace vector<unique_ptr<File> with unique_ptr<File>.
>
> Because each InputElement has exactly one File, we no longer have
> to use a vector to store pointers to Files.
>
> Modified:
>     lld/trunk/include/lld/Core/InputGraph.h
>     lld/trunk/include/lld/Driver/WrapperInputGraph.h
>     lld/trunk/lib/Core/InputGraph.cpp
>     lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
>
> Modified: lld/trunk/include/lld/Core/InputGraph.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/InputGraph.h?rev=225814&r1=225813&r2=225814&view=diff
>
> ==============================================================================
> --- lld/trunk/include/lld/Core/InputGraph.h (original)
> +++ lld/trunk/include/lld/Core/InputGraph.h Tue Jan 13 12:47:25 2015
> @@ -148,7 +148,7 @@ private:
>  class FileNode : public InputElement {
>  public:
>    FileNode(StringRef path)
> -      : InputElement(InputElement::Kind::File), _path(path),
> _nextFileIndex(0) {
> +      : InputElement(InputElement::Kind::File), _path(path), _done(false)
> {
>    }
>
>    virtual ErrorOr<StringRef> getPath(const LinkingContext &) const {
> @@ -169,35 +169,33 @@ public:
>    }
>
>    /// \brief Get the list of files
> -  range<InputGraph::FileIterT> files() {
> -    return make_range(_files.begin(), _files.end());
> -  }
> +  File *getFile() { return _file.get(); }
>
>    /// \brief add a file to the list of files
>    virtual void addFiles(InputGraph::FileVectorT files) {
>      assert(files.size() == 1);
> -    assert(_files.empty());
> -    for (std::unique_ptr<File> &ai : files)
> -      _files.push_back(std::move(ai));
> +    assert(!_file);
> +    _file.swap(files[0]);


_file = std::move(files[0]);

perhaps?


>    }
>
>    /// \brief Return the next File thats part of this node to the
>    /// resolver.
>    File *getNextFile() override {
> -    assert(_files.size() == 1);
> -    if (_nextFileIndex == _files.size())
> +    assert(_file);
> +    if (_done)
>        return nullptr;
> -    return _files[_nextFileIndex++].get();
> +    _done = true;
> +    return _file.get();
>    }
>
>    std::error_code parse(const LinkingContext &, raw_ostream &) override;
>
>  protected:
>    StringRef _path;                       // The path of the Input file
> -  InputGraph::FileVectorT _files;        // A vector of lld File objects
> +  std::unique_ptr<File> _file;        // A vector of lld File objects
>
>    // The next file that would be processed by the resolver
> -  uint32_t _nextFileIndex;
> +  bool _done;
>  };
>
>  /// \brief Represents Internal Input files
> @@ -206,14 +204,14 @@ public:
>    SimpleFileNode(StringRef path) : FileNode(path) {}
>    SimpleFileNode(StringRef path, std::unique_ptr<File> f)
>        : FileNode(path) {
> -    _files.push_back(std::move(f));
> +    _file.swap(f);
>

Use the init list?

: FileNode(path), _file(std::move(f)) {
}


>    }
>
>    virtual ~SimpleFileNode() {}
>
>    /// \brief add a file to the list of files
>    virtual void appendInputFile(std::unique_ptr<File> f) {
> -    _files.push_back(std::move(f));
> +    _file.swap(f);
>

_file = std::move(f);


>    }
>  };
>
>
> Modified: lld/trunk/include/lld/Driver/WrapperInputGraph.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/WrapperInputGraph.h?rev=225814&r1=225813&r2=225814&view=diff
>
> ==============================================================================
> --- lld/trunk/include/lld/Driver/WrapperInputGraph.h (original)
> +++ lld/trunk/include/lld/Driver/WrapperInputGraph.h Tue Jan 13 12:47:25
> 2015
> @@ -22,7 +22,7 @@ namespace lld {
>  class WrapperNode : public FileNode {
>  public:
>    WrapperNode(std::unique_ptr<File> file) : FileNode(file->path()) {
> -    _files.push_back(std::move(file));
> +    _file.swap(file);
>

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?)


>    }
>  };
>
>
> Modified: lld/trunk/lib/Core/InputGraph.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/InputGraph.cpp?rev=225814&r1=225813&r2=225814&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/Core/InputGraph.cpp (original)
> +++ lld/trunk/lib/Core/InputGraph.cpp Tue Jan 13 12:47:25 2015
> @@ -69,8 +69,8 @@ void InputGraph::skipGroup() {
>  }
>
>  std::error_code FileNode::parse(const LinkingContext &, raw_ostream &) {
> -  for (std::unique_ptr<File> &file : _files)
> -    if (std::error_code ec = file->parse())
> +  if (_file)
> +    if (std::error_code ec = _file->parse())
>        return ec;
>    return std::error_code();
>  }
>
> Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=225814&r1=225813&r2=225814&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
> +++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Tue Jan 13
> 12:47:25 2015
> @@ -928,9 +928,7 @@ bool MachOLinkingContext::customAtomOrde
>
>  static File *getFirstFile(const std::unique_ptr<InputElement> &elem) {
>    FileNode *e = dyn_cast<FileNode>(const_cast<InputElement
> *>(elem.get()));
> -  if (!e || e->files().empty())
> -    return nullptr;
> -  return e->files()[0].get();
> +  return e ? e->getFile() : nullptr;
>  }
>
>  static bool isLibrary(const std::unique_ptr<InputElement> &elem) {
>
>
> _______________________________________________
> 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/20150113/0b52e7e4/attachment.html>


More information about the llvm-commits mailing list