summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeisuke Kuroyanagi <ksk@google.com>2016-02-02 19:48:04 +0900
committerKeisuke Kuroyanagi <ksk@google.com>2016-02-08 06:56:56 +0000
commit9d48271c0480c27402cfba359f45964637927a63 (patch)
treedf294a04528f64ff5901200b7bdb52e8960ecd53
parent89e80237bc27af084c9ff316d4f47abf426eced8 (diff)
downloadandroid_frameworks_minikin-9d48271c0480c27402cfba359f45964637927a63.tar.gz
android_frameworks_minikin-9d48271c0480c27402cfba359f45964637927a63.tar.bz2
android_frameworks_minikin-9d48271c0480c27402cfba359f45964637927a63.zip
Optimize: Precompute the hash value for LayoutCacheKey.
Bug: 24505153 Change-Id: If61c063c175086dec88cda187eafd9ce923e4cb1
-rw-r--r--libs/minikin/Layout.cpp13
1 files changed, 10 insertions, 3 deletions
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<LayoutCacheKey, Layout*> {
@@ -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);