summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/include/lld/Core/InputGraph.h26
-rw-r--r--lld/include/lld/Driver/WrapperInputGraph.h2
-rw-r--r--lld/lib/Core/InputGraph.cpp4
-rw-r--r--lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp4
4 files changed, 16 insertions, 20 deletions
diff --git a/lld/include/lld/Core/InputGraph.h b/lld/include/lld/Core/InputGraph.h
index 65eb060f1d8..8ccb4438b1d 100644
--- a/lld/include/lld/Core/InputGraph.h
+++ b/lld/include/lld/Core/InputGraph.h
@@ -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);
}
};
diff --git a/lld/include/lld/Driver/WrapperInputGraph.h b/lld/include/lld/Driver/WrapperInputGraph.h
index 778823b7a5e..cb2a085fc3b 100644
--- a/lld/include/lld/Driver/WrapperInputGraph.h
+++ b/lld/include/lld/Driver/WrapperInputGraph.h
@@ -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);
}
};
diff --git a/lld/lib/Core/InputGraph.cpp b/lld/lib/Core/InputGraph.cpp
index 1ecd1ebbcd0..1fad727647f 100644
--- a/lld/lib/Core/InputGraph.cpp
+++ b/lld/lib/Core/InputGraph.cpp
@@ -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();
}
diff --git a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
index 37591d0f546..201d1f85b96 100644
--- a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
@@ -928,9 +928,7 @@ bool MachOLinkingContext::customAtomOrderer(const DefinedAtom *left,
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) {
OpenPOWER on IntegriCloud