From f69a0029118f7c05964db98f374a0eaec8f4ba1b Mon Sep 17 00:00:00 2001 From: Edwin Smith Date: Fri, 7 Jun 2013 10:14:18 -0700 Subject: [PATCH] Remove the SharedVariant pointer from StringData. We only use it to lazily grab the hashcode. So just grab the hashcode eagerly when we create the string. --- hphp/runtime/base/string_data.cpp | 7 +++---- hphp/runtime/base/string_data.h | 12 ++---------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/hphp/runtime/base/string_data.cpp b/hphp/runtime/base/string_data.cpp index a3e8a6355..59ebe8eb5 100644 --- a/hphp/runtime/base/string_data.cpp +++ b/hphp/runtime/base/string_data.cpp @@ -300,10 +300,9 @@ HOT_FUNC StringData::StringData(SharedVariant *shared) : _count(0) { assert(shared && size_t(shared->stringLength()) <= size_t(MaxSize)); - m_hash = 0; + m_hash = shared->stringHash(); m_len = shared->stringLength(); m_cdata = shared->stringData(); - m_big.shared = shared; m_big.cap = m_len | IsShared; } @@ -914,8 +913,8 @@ int StringData::compare(const StringData *v2) const { HOT_FUNC strhash_t StringData::hashHelper() const { - strhash_t h = isShared() ? m_big.shared->stringHash() : - hash_string_inline(m_data, m_len); + assert(!isShared()); + strhash_t h = hash_string_inline(m_data, m_len); assert(h >= 0); m_hash |= h; return h; diff --git a/hphp/runtime/base/string_data.h b/hphp/runtime/base/string_data.h index cf4ccf89a..3929ef81b 100644 --- a/hphp/runtime/base/string_data.h +++ b/hphp/runtime/base/string_data.h @@ -87,7 +87,7 @@ enum CopyMallocMode { CopyMalloc }; * small: m_data:8, _count:4, m_len:4, m_hash:4, * m_small[44] * big: m_data:8, _count:4, m_len:4, m_hash:4, - * junk[12], node:16, shared:8, cap:8 + * junk[36], cap:8 * * If the format is IsLiteral or IsShared, we always use the "big" layout. * resemblences to fbstring are not accidental. @@ -137,7 +137,6 @@ class StringData { void destruct() const { if (!isStatic()) delete this; } StringData() : m_data(m_small), _count(0), m_len(0), m_hash(0) { - m_big.shared = 0; m_big.cap = IsSmall; m_small[0] = 0; } @@ -301,11 +300,6 @@ public: double toDouble () const; DataType toNumeric(int64_t &lval, double &dval) const; - strhash_t getPrecomputedHash() const { - assert(!isShared()); - return m_hash & STRHASH_MASK; - } - strhash_t hash() const { strhash_t h = m_hash & STRHASH_MASK; return h ? h : hashHelper(); @@ -375,10 +369,8 @@ public: struct __attribute__((__packed__)) { // Calculate padding so that node, shared, and cap are pointer aligned, // and ensure cap overlaps the last byte of m_small. - static const size_t kPadding = sizeof(m_small) - - sizeof(SharedVariant*) - sizeof(uint64_t); + static const size_t kPadding = sizeof(m_small) - sizeof(uint64_t); char junk[kPadding]; - SharedVariant *shared; uint64_t cap; } m_big; };