Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Unified Diff: runtime/vm/object.h

Issue 2889723005: Revert "More compact string representation on 64 bit." (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/intrinsifier_x64.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.h
diff --git a/runtime/vm/object.h b/runtime/vm/object.h
index 954db0401dcc852c3a05e96012264734fc88930f..603467775b9072d2a688818e3bf1ac6d66e6ecaa 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -432,18 +432,6 @@ class Object {
return *transition_sentinel_;
}
-#if defined(HASH_IN_OBJECT_HEADER)
- static uint32_t GetCachedHash(const RawObject* obj) {
- uword tags = obj->ptr()->tags_;
- return tags >> 32;
- }
-
- static void SetCachedHash(RawObject* obj, uintptr_t hash) {
- ASSERT(hash >> 32 == 0);
- obj->ptr()->tags_ |= hash << 32;
- }
-#endif
-
// Compiler's constant propagation constants.
static const Instance& unknown_constant() {
ASSERT(unknown_constant_ != NULL);
@@ -6764,11 +6752,8 @@ class String : public Instance {
// All strings share the same maximum element count to keep things
// simple. We choose a value that will prevent integer overflow for
// 2 byte strings, since it is the worst case.
-#if defined(HASH_IN_OBJECT_HEADER)
- static const intptr_t kSizeofRawString = sizeof(RawInstance) + kWordSize;
-#else
- static const intptr_t kSizeofRawString = sizeof(RawInstance) + 2 * kWordSize;
-#endif
+ static const intptr_t kSizeofRawString =
+ sizeof(RawInstance) + (2 * kWordSize);
static const intptr_t kMaxElements = kSmiMax / kTwoByteChar;
class CodePointIterator : public ValueObject {
@@ -6804,32 +6789,28 @@ class String : public Instance {
static intptr_t length_offset() { return OFFSET_OF(RawString, length_); }
intptr_t Hash() const {
- intptr_t result = GetCachedHash(raw());
+ intptr_t result = Smi::Value(raw_ptr()->hash_);
if (result != 0) {
return result;
}
result = String::Hash(*this, 0, this->Length());
- SetCachedHash(raw(), result);
+ this->SetHash(result);
return result;
}
bool HasHash() const {
ASSERT(Smi::New(0) == NULL);
- return GetCachedHash(raw()) != 0;
+ return (raw_ptr()->hash_ != NULL);
}
-#if defined(HASH_IN_OBJECT_HEADER)
- static intptr_t hash_offset() { return kInt32Size; } // Wrong for big-endian?
-#else
static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); }
-#endif
static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len);
static intptr_t Hash(const char* characters, intptr_t len);
static intptr_t Hash(const uint16_t* characters, intptr_t len);
static intptr_t Hash(const int32_t* characters, intptr_t len);
static intptr_t HashRawSymbol(const RawString* symbol) {
ASSERT(symbol->IsCanonical());
- intptr_t result = GetCachedHash(symbol);
+ intptr_t result = Smi::Value(symbol->ptr()->hash_);
ASSERT(result != 0);
return result;
}
@@ -7048,16 +7029,6 @@ class String : public Instance {
intptr_t end,
double* result);
-#if !defined(HASH_IN_OBJECT_HEADER)
- static uint32_t GetCachedHash(const RawString* obj) {
- return Smi::Value(obj->ptr()->hash_);
- }
-
- static void SetCachedHash(RawString* obj, uintptr_t hash) {
- obj->ptr()->hash_ = Smi::New(hash);
- }
-#endif
-
protected:
// These two operate on an array of Latin-1 encoded characters.
// They are protected to avoid mistaking Latin-1 for UTF-8, but used
@@ -7071,7 +7042,11 @@ class String : public Instance {
StoreSmi(&raw_ptr()->length_, Smi::New(value));
}
- void SetHash(intptr_t value) const { SetCachedHash(raw(), value); }
+ void SetHash(intptr_t value) const {
+ // This is only safe because we create a new Smi, which does not cause
+ // heap allocation.
+ StoreSmi(&raw_ptr()->hash_, Smi::New(value));
+ }
template <typename HandleType, typename ElementType, typename CallbackType>
static void ReadFromImpl(SnapshotReader* reader,
@@ -7130,12 +7105,6 @@ class OneByteString : public AllStatic {
static intptr_t InstanceSize(intptr_t len) {
ASSERT(sizeof(RawOneByteString) == String::kSizeofRawString);
ASSERT(0 <= len && len <= kMaxElements);
-#if defined(HASH_IN_OBJECT_HEADER)
- // We have to pad zero-length raw strings so that they can be externalized.
- // If we don't pad, then the external string object does not fit in the
- // memory allocated for the raw string.
- if (len == 0) return InstanceSize(1);
-#endif
return String::RoundedAllocationSize(sizeof(RawOneByteString) +
(len * kBytesPerElement));
}
@@ -7269,10 +7238,6 @@ class TwoByteString : public AllStatic {
static intptr_t InstanceSize(intptr_t len) {
ASSERT(sizeof(RawTwoByteString) == String::kSizeofRawString);
ASSERT(0 <= len && len <= kMaxElements);
- // We have to pad zero-length raw strings so that they can be externalized.
- // If we don't pad, then the external string object does not fit in the
- // memory allocated for the raw string.
- if (len == 0) return InstanceSize(1);
return String::RoundedAllocationSize(sizeof(RawTwoByteString) +
(len * kBytesPerElement));
}
@@ -8966,7 +8931,7 @@ bool String::Equals(const String& str) const {
intptr_t Library::UrlHash() const {
- intptr_t result = String::GetCachedHash(url());
+ intptr_t result = Smi::Value(url()->ptr()->hash_);
ASSERT(result != 0);
return result;
}
« no previous file with comments | « runtime/vm/intrinsifier_x64.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698