diff options
| author | 2018-01-29 16:34:46 +0000 | |
|---|---|---|
| committer | 2018-01-29 16:34:46 +0000 | |
| commit | 554a7e5f40c62970848e04632c8c31316842dcc7 (patch) | |
| tree | 77608c4862843b910572584c8c5089cada030690 | |
| parent | 58ddad4e8b003ed1c85d4c179857a619ed2c8eef (diff) | |
| parent | 807b21b2364eee0770d1e24e5f34d71014afbac2 (diff) | |
Merge "Clean up some compact dex comments"
| -rw-r--r-- | dexlayout/compact_dex_writer.cc | 7 | ||||
| -rw-r--r-- | dexlayout/dex_ir_builder.h | 4 | ||||
| -rw-r--r-- | dexlayout/dexlayout.h | 2 | ||||
| -rw-r--r-- | dexlayout/dexlayout_test.cc | 4 |
4 files changed, 11 insertions, 6 deletions
diff --git a/dexlayout/compact_dex_writer.cc b/dexlayout/compact_dex_writer.cc index 092539fe93..08438c4f4a 100644 --- a/dexlayout/compact_dex_writer.cc +++ b/dexlayout/compact_dex_writer.cc @@ -121,11 +121,14 @@ CompactDexWriter::ScopedDataSectionItem::~ScopedDataSectionItem() { const uint32_t deduped_offset = deduper_->Dedupe(start_offset_, stream_->Tell(), item_->GetOffset()); - // In case we dedupe to something with wrong alignment, just say we didn't dedupe. + // If we deduped, only use the deduped offset if the alignment matches the required alignment. + // Otherwise, return without deduping. if (deduped_offset != Deduper::kDidNotDedupe && IsAlignedParam(deduped_offset, alignment_)) { + // Update the IR offset to the offset of the deduped item. item_->SetOffset(deduped_offset); + // Clear the written data for the item so that the stream write doesn't abort in the future. stream_->Clear(start_offset_, stream_->Tell() - start_offset_); - // Undo the offset for all that we wrote since we deduped. + // Since we deduped, restore the offset to the original position. stream_->Seek(start_offset_); } } diff --git a/dexlayout/dex_ir_builder.h b/dexlayout/dex_ir_builder.h index 43b5290756..9f5377fe56 100644 --- a/dexlayout/dex_ir_builder.h +++ b/dexlayout/dex_ir_builder.h @@ -27,8 +27,8 @@ class Options; namespace dex_ir { -// Eagerly assign offsets assigns offsets based on the original offsets in the input dex file. If -// this not done, dex_ir::Item::GetOffset will abort when reading uninitialized offsets. +// Eagerly assign offsets based on the original offsets in the input dex file. If this is not done, +// dex_ir::Item::GetOffset will abort when reading uninitialized offsets. dex_ir::Header* DexIrBuilder(const DexFile& dex_file, bool eagerly_assign_offsets, const Options& options); diff --git a/dexlayout/dexlayout.h b/dexlayout/dexlayout.h index e66710fa55..d2f9cb9ce5 100644 --- a/dexlayout/dexlayout.h +++ b/dexlayout/dexlayout.h @@ -72,6 +72,8 @@ class Options { const char* output_dex_directory_ = nullptr; const char* output_file_name_ = nullptr; const char* profile_file_name_ = nullptr; + // Filter that removes classes that don't have a matching descriptor (during IR creation). + // This speeds up cases when the output only requires a single class. std::set<std::string> class_filter_; }; diff --git a/dexlayout/dexlayout_test.cc b/dexlayout/dexlayout_test.cc index e93ade1412..be272fcf2c 100644 --- a/dexlayout/dexlayout_test.cc +++ b/dexlayout/dexlayout_test.cc @@ -823,9 +823,9 @@ TEST_F(DexLayoutTest, ClassFilter) { &error_msg)); ASSERT_TRUE(output_dex_file != nullptr); - ASSERT_EQ(output_dex_file->NumClassDefs(), 1u); + ASSERT_EQ(output_dex_file->NumClassDefs(), options.class_filter_.size()); for (uint32_t i = 0; i < output_dex_file->NumClassDefs(); ++i) { - // Check that every class is in the filter. + // Check that every class in the output dex file is in the filter. const DexFile::ClassDef& class_def = output_dex_file->GetClassDef(i); ASSERT_TRUE(options.class_filter_.find(output_dex_file->GetClassDescriptor(class_def)) != options.class_filter_.end()); |