summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Marko <vmarko@google.com>2014-06-09 09:16:36 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-06-09 09:16:37 +0000
commitfbc2b1747e7e3d06f214f801f53218a1d4bf2dbe (patch)
tree4511cf6d65d9958fee838cf508cc3b16ed3048ac
parent7c2e21d9e39c6b6cf0c5bdff0101fc70c202c908 (diff)
parent539690a351d8c325707368729aafa2b4fa134d4c (diff)
downloadart-fbc2b1747e7e3d06f214f801f53218a1d4bf2dbe.zip
art-fbc2b1747e7e3d06f214f801f53218a1d4bf2dbe.tar.gz
art-fbc2b1747e7e3d06f214f801f53218a1d4bf2dbe.tar.bz2
Merge "Avoid a memory allocation in OatFile::GetOatDexFile()."
-rw-r--r--runtime/oat_file.cc13
-rw-r--r--runtime/oat_file.h15
2 files changed, 17 insertions, 11 deletions
diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc
index 74dfe91..6c44aa9 100644
--- a/runtime/oat_file.cc
+++ b/runtime/oat_file.cc
@@ -292,11 +292,14 @@ bool OatFile::Setup(std::string* error_msg) {
return false;
}
- oat_dex_files_.Put(dex_file_location, new OatDexFile(this,
- dex_file_location,
- dex_file_checksum,
- dex_file_pointer,
- methods_offsets_pointer));
+ OatDexFile* oat_dex_file = new OatDexFile(this,
+ dex_file_location,
+ dex_file_checksum,
+ dex_file_pointer,
+ methods_offsets_pointer);
+ // Use a StringPiece backed by the oat_dex_file's internal std::string as the key.
+ StringPiece key(oat_dex_file->GetDexFileLocation());
+ oat_dex_files_.Put(key, oat_dex_file);
}
return true;
}
diff --git a/runtime/oat_file.h b/runtime/oat_file.h
index d703731..eae0418 100644
--- a/runtime/oat_file.h
+++ b/runtime/oat_file.h
@@ -20,6 +20,7 @@
#include <string>
#include <vector>
+#include "base/stringpiece.h"
#include "dex_file.h"
#include "invoke_type.h"
#include "mem_map.h"
@@ -206,11 +207,11 @@ class OatFile {
const byte* dex_file_pointer,
const uint32_t* oat_class_offsets_pointer);
- const OatFile* oat_file_;
- std::string dex_file_location_;
- uint32_t dex_file_location_checksum_;
- const byte* dex_file_pointer_;
- const uint32_t* oat_class_offsets_pointer_;
+ const OatFile* const oat_file_;
+ const std::string dex_file_location_;
+ const uint32_t dex_file_location_checksum_;
+ const byte* const dex_file_pointer_;
+ const uint32_t* const oat_class_offsets_pointer_;
friend class OatFile;
DISALLOW_COPY_AND_ASSIGN(OatDexFile);
@@ -270,7 +271,9 @@ class OatFile {
// dlopen handle during runtime.
void* dlopen_handle_;
- typedef SafeMap<std::string, const OatDexFile*> Table;
+ // NOTE: We use a StringPiece as the key type to avoid a memory allocation on every lookup
+ // with a const char* key.
+ typedef SafeMap<StringPiece, const OatDexFile*> Table;
Table oat_dex_files_;
friend class OatClass;