summaryrefslogtreecommitdiff
path: root/tools/aapt2/io
diff options
context:
space:
mode:
authorPierre Lecesne <lecesne@google.com>2017-02-02 22:33:17 +0000
committerPierre Lecesne <lecesne@google.com>2017-02-02 22:52:44 +0000
commit880d65b4fdfcdc5ac24a3d697a2acfc8511d8b37 (patch)
treeafca5c8fd9417eac0f150585a64d4724089994d6 /tools/aapt2/io
parentddb80216b9d536be0f2af287f44a41872aa1d809 (diff)
Iterate over the zip entries in order.
Test: Unit tests pass. Change-Id: I0501fad51a87c6cc91f2fc22358cd356616e1a2e
Diffstat (limited to 'tools/aapt2/io')
-rw-r--r--tools/aapt2/io/ZipArchive.cpp14
-rw-r--r--tools/aapt2/io/ZipArchive.h5
2 files changed, 11 insertions, 8 deletions
diff --git a/tools/aapt2/io/ZipArchive.cpp b/tools/aapt2/io/ZipArchive.cpp
index 62b436fe4dc7..bafaa7bf3dcd 100644
--- a/tools/aapt2/io/ZipArchive.cpp
+++ b/tools/aapt2/io/ZipArchive.cpp
@@ -66,7 +66,7 @@ ZipFileCollectionIterator::ZipFileCollectionIterator(
bool ZipFileCollectionIterator::HasNext() { return current_ != end_; }
IFile* ZipFileCollectionIterator::Next() {
- IFile* result = current_->second.get();
+ IFile* result = current_->get();
++current_;
return result;
}
@@ -110,8 +110,10 @@ std::unique_ptr<ZipFileCollection> ZipFileCollection::Create(
std::string(reinterpret_cast<const char*>(zip_entry_name.name),
zip_entry_name.name_length);
std::string nested_path = path.to_string() + "@" + zip_entry_path;
- collection->files_[zip_entry_path] = util::make_unique<ZipFile>(
- collection->handle_, zip_data, Source(nested_path));
+ std::unique_ptr<IFile> file =
+ util::make_unique<ZipFile>(collection->handle_, zip_data, Source(nested_path));
+ collection->files_by_name_[zip_entry_path] = file.get();
+ collection->files_.push_back(std::move(file));
}
if (result != -1) {
@@ -122,9 +124,9 @@ std::unique_ptr<ZipFileCollection> ZipFileCollection::Create(
}
IFile* ZipFileCollection::FindFile(const StringPiece& path) {
- auto iter = files_.find(path.to_string());
- if (iter != files_.end()) {
- return iter->second.get();
+ auto iter = files_by_name_.find(path.to_string());
+ if (iter != files_by_name_.end()) {
+ return iter->second;
}
return nullptr;
}
diff --git a/tools/aapt2/io/ZipArchive.h b/tools/aapt2/io/ZipArchive.h
index 634adad8af32..c72cfda263a8 100644
--- a/tools/aapt2/io/ZipArchive.h
+++ b/tools/aapt2/io/ZipArchive.h
@@ -57,7 +57,7 @@ class ZipFileCollectionIterator : public IFileCollectionIterator {
io::IFile* Next() override;
private:
- std::map<std::string, std::unique_ptr<IFile>>::const_iterator current_, end_;
+ std::vector<std::unique_ptr<IFile>>::const_iterator current_, end_;
};
/**
@@ -78,7 +78,8 @@ class ZipFileCollection : public IFileCollection {
ZipFileCollection();
ZipArchiveHandle handle_;
- std::map<std::string, std::unique_ptr<IFile>> files_;
+ std::vector<std::unique_ptr<IFile>> files_;
+ std::map<std::string, IFile*> files_by_name_;
};
} // namespace io