[lld] r225814 - Replace vector<unique_ptr<File> with unique_ptr<File>.
Rui Ueyama
ruiu at google.com
Tue Jan 13 10:47:26 PST 2015
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]);
}
/// \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);
}
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);
}
};
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);
}
};
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) {
More information about the llvm-commits
mailing list