summaryrefslogtreecommitdiff
path: root/runtime/string_reference.h
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/string_reference.h')
-rw-r--r--runtime/string_reference.h29
1 files changed, 11 insertions, 18 deletions
diff --git a/runtime/string_reference.h b/runtime/string_reference.h
index 6ba47736ec..d0ab4e40d0 100644
--- a/runtime/string_reference.h
+++ b/runtime/string_reference.h
@@ -21,37 +21,30 @@
#include "base/logging.h"
#include "dex_file-inl.h"
+#include "dex_file_reference.h"
#include "dex_file_types.h"
#include "utf-inl.h"
namespace art {
// A string is located by its DexFile and the string_ids_ table index into that DexFile.
-struct StringReference {
+class StringReference : public DexFileReference {
+ public:
StringReference(const DexFile* file, dex::StringIndex index)
- : dex_file(file), string_index(index) { }
+ : DexFileReference(file, index.index_) {}
- const char* GetStringData() const {
- return dex_file->GetStringData(dex_file->GetStringId(string_index));
+ dex::StringIndex StringIndex() const {
+ return dex::StringIndex(index);
}
- const DexFile* dex_file;
- dex::StringIndex string_index;
-};
-
-// Compare only the reference and not the string contents.
-struct StringReferenceComparator {
- bool operator()(const StringReference& a, const StringReference& b) const {
- if (a.dex_file != b.dex_file) {
- return a.dex_file < b.dex_file;
- }
- return a.string_index < b.string_index;
+ const char* GetStringData() const {
+ return dex_file->GetStringData(dex_file->GetStringId(StringIndex()));
}
};
// Compare the actual referenced string values. Used for string reference deduplication.
struct StringReferenceValueComparator {
- bool operator()(StringReference sr1, StringReference sr2) const {
+ bool operator()(const StringReference& sr1, const StringReference& sr2) const {
// Note that we want to deduplicate identical strings even if they are referenced
// by different dex files, so we need some (any) total ordering of strings, rather
// than references. However, the references should usually be from the same dex file,
@@ -60,10 +53,10 @@ struct StringReferenceValueComparator {
if (sr1.dex_file == sr2.dex_file) {
// Use the string order enforced by the dex file verifier.
DCHECK_EQ(
- sr1.string_index < sr2.string_index,
+ sr1.index < sr2.index,
CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(sr1.GetStringData(),
sr2.GetStringData()) < 0);
- return sr1.string_index < sr2.string_index;
+ return sr1.index < sr2.index;
} else {
// Cannot compare indexes, so do the string comparison.
return CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(sr1.GetStringData(),