From 9d48271c0480c27402cfba359f45964637927a63 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Tue, 2 Feb 2016 19:48:04 +0900 Subject: Optimize: Precompute the hash value for LayoutCacheKey. Bug: 24505153 Change-Id: If61c063c175086dec88cda187eafd9ce923e4cb1 --- libs/minikin/Layout.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'libs') diff --git a/libs/minikin/Layout.cpp b/libs/minikin/Layout.cpp index 71e0d89..3a05acf 100644 --- a/libs/minikin/Layout.cpp +++ b/libs/minikin/Layout.cpp @@ -114,10 +114,14 @@ public: mStart(start), mCount(count), mId(collection->getId()), mStyle(style), mSize(paint.size), mScaleX(paint.scaleX), mSkewX(paint.skewX), mLetterSpacing(paint.letterSpacing), - mPaintFlags(paint.paintFlags), mHyphenEdit(paint.hyphenEdit), mIsRtl(dir) { + mPaintFlags(paint.paintFlags), mHyphenEdit(paint.hyphenEdit), mIsRtl(dir), + mHash(computeHash()) { } bool operator==(const LayoutCacheKey &other) const; - hash_t hash() const; + + hash_t hash() const { + return mHash; + } void copyText() { uint16_t* charsCopy = new uint16_t[mNchars]; @@ -152,6 +156,9 @@ private: bool mIsRtl; // Note: any fields added to MinikinPaint must also be reflected here. // TODO: language matching (possibly integrate into style) + hash_t mHash; + + hash_t computeHash() const; }; class LayoutCache : private OnEntryRemoved { @@ -230,7 +237,7 @@ bool LayoutCacheKey::operator==(const LayoutCacheKey& other) const { && !memcmp(mChars, other.mChars, mNchars * sizeof(uint16_t)); } -hash_t LayoutCacheKey::hash() const { +hash_t LayoutCacheKey::computeHash() const { uint32_t hash = JenkinsHashMix(0, mId); hash = JenkinsHashMix(hash, mStart); hash = JenkinsHashMix(hash, mCount); -- cgit v1.2.3