summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libdexfile/dex/dex_file.cc16
-rw-r--r--libdexfile/dex/dex_file.h20
2 files changed, 23 insertions, 13 deletions
diff --git a/libdexfile/dex/dex_file.cc b/libdexfile/dex/dex_file.cc
index c2b478aded..47a6c1b6b7 100644
--- a/libdexfile/dex/dex_file.cc
+++ b/libdexfile/dex/dex_file.cc
@@ -99,6 +99,11 @@ DexFile::DexFile(std::unique_ptr<DexFileContainer> main_section,
const OatDexFile* oat_dex_file,
bool is_compact_dex)
: main_section_(std::move(main_section)),
+ main_begin_(main_section_->Begin()),
+ main_size_(main_section_->Size()),
+ data_section_(std::move(data_section)),
+ data_begin_(data_section_->Begin()),
+ data_size_(data_section_->Size()),
location_(location),
location_checksum_(location_checksum),
header_(reinterpret_cast<const Header*>(main_section_->Begin())),
@@ -127,8 +132,6 @@ DexFile::DexFile(std::unique_ptr<DexFileContainer> main_section,
// any of the sections via a pointer.
CHECK_ALIGNED(main_section_->Begin(), alignof(Header));
- data_section_ = std::move(data_section);
-
InitializeSectionsFromMapList();
}
@@ -138,6 +141,12 @@ DexFile::DexFile(std::unique_ptr<DexFileContainer> main_section,
const OatDexFile* oat_dex_file,
bool is_compact_dex)
: main_section_(std::move(main_section)),
+ main_begin_(main_section_->Begin()),
+ main_size_(main_section_->Size()),
+ data_section_(std::make_unique<NonOwningDexFileContainer>(main_section_->Begin(),
+ main_section_->Size())),
+ data_begin_(data_section_->Begin()),
+ data_size_(data_section_->Size()),
location_(location),
location_checksum_(location_checksum),
header_(reinterpret_cast<const Header*>(main_section_->Begin())),
@@ -166,9 +175,6 @@ DexFile::DexFile(std::unique_ptr<DexFileContainer> main_section,
// any of the sections via a pointer.
CHECK_ALIGNED(main_section_->Begin(), alignof(Header));
- data_section_ = std::make_unique<NonOwningDexFileContainer>(main_section_->Begin(),
- main_section_->Size());
-
InitializeSectionsFromMapList();
}
diff --git a/libdexfile/dex/dex_file.h b/libdexfile/dex/dex_file.h
index c94c786699..714e42cb3c 100644
--- a/libdexfile/dex/dex_file.h
+++ b/libdexfile/dex/dex_file.h
@@ -966,19 +966,19 @@ class DexFile {
bool DisableWrite() const;
const uint8_t* Begin() const {
- return main_section_->Begin();
+ return main_begin_;
}
size_t Size() const {
- return main_section_->Size();
+ return main_size_;
}
const uint8_t* DataBegin() const {
- return data_section_->Begin();
+ return data_begin_;
}
size_t DataSize() const {
- return data_section_->Size();
+ return data_size_;
}
template <typename T>
@@ -1089,10 +1089,14 @@ class DexFile {
void InitializeSectionsFromMapList();
// The container for the header and fixed portions.
- std::unique_ptr<DexFileContainer> main_section_;
-
- // The container for the data section
- std::unique_ptr<DexFileContainer> data_section_;
+ const std::unique_ptr<DexFileContainer> main_section_;
+ const uint8_t* const main_begin_;
+ const size_t main_size_;
+
+ // The container for the data section.
+ const std::unique_ptr<DexFileContainer> data_section_;
+ const uint8_t* const data_begin_;
+ const size_t data_size_;
// Typically the dex file name when available, alternatively some identifying string.
//