From 380658778eb18b611b37a360b246d8045cbc4c47 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Tue, 2 Feb 2016 19:48:04 +0900 Subject: [PATCH] Optimize: Precompute the hash value for LayoutCacheKey. Bug: 24505153 Change-Id: If61c063c175086dec88cda187eafd9ce923e4cb1 --- engine/src/flutter/libs/minikin/Layout.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 71e0d890b7..3a05acfd9d 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/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);