diff --git a/tools/aapt2/io/ZipArchive.cpp b/tools/aapt2/io/ZipArchive.cpp index debc484bca925..6494d2def748c 100644 --- a/tools/aapt2/io/ZipArchive.cpp +++ b/tools/aapt2/io/ZipArchive.cpp @@ -70,7 +70,7 @@ ZipFileCollectionIterator::ZipFileCollectionIterator( bool ZipFileCollectionIterator::HasNext() { return current_ != end_; } IFile* ZipFileCollectionIterator::Next() { - IFile* result = current_->second.get(); + IFile* result = current_->get(); ++current_; return result; } @@ -114,8 +114,10 @@ std::unique_ptr ZipFileCollection::Create( std::string(reinterpret_cast(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( - collection->handle_, zip_data, Source(nested_path)); + std::unique_ptr file = + util::make_unique(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) { @@ -126,9 +128,9 @@ std::unique_ptr 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 f47287f32e9be..56c74e326e6c8 100644 --- a/tools/aapt2/io/ZipArchive.h +++ b/tools/aapt2/io/ZipArchive.h @@ -58,7 +58,7 @@ class ZipFileCollectionIterator : public IFileCollectionIterator { io::IFile* Next() override; private: - std::map>::const_iterator current_, end_; + std::vector>::const_iterator current_, end_; }; /** @@ -79,7 +79,8 @@ class ZipFileCollection : public IFileCollection { ZipFileCollection(); ZipArchiveHandle handle_; - std::map> files_; + std::vector> files_; + std::map files_by_name_; }; } // namespace io