diff options
-rw-r--r-- | core/jni/android/graphics/TextLayoutCache.cpp | 46 | ||||
-rw-r--r-- | core/jni/android/graphics/TextLayoutCache.h | 17 |
2 files changed, 38 insertions, 25 deletions
diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp index 86ae7d2..3c70c30 100644 --- a/core/jni/android/graphics/TextLayoutCache.cpp +++ b/core/jni/android/graphics/TextLayoutCache.cpp @@ -251,26 +251,32 @@ TextLayoutCacheKey::TextLayoutCacheKey(const TextLayoutCacheKey& other) : } } -bool TextLayoutCacheKey::operator<(const TextLayoutCacheKey& rhs) const { - LTE_INT(count) { - LTE_INT(typeface) { - LTE_FLOAT(textSize) { - LTE_FLOAT(textSkewX) { - LTE_FLOAT(textScaleX) { - LTE_INT(flags) { - LTE_INT(hinting) { - LTE_INT(dirFlags) { - return memcmp(getText(), rhs.getText(), - count * sizeof(UChar)) < 0; - } - } - } - } - } - } - } - } - return false; +int TextLayoutCacheKey::compare(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs) { + int deltaInt = lhs.count - rhs.count; + if (deltaInt != 0) return (deltaInt); + + if (lhs.typeface < rhs.typeface) return -1; + if (lhs.typeface > rhs.typeface) return +1; + + if (lhs.textSize < rhs.textSize) return -1; + if (lhs.textSize > rhs.textSize) return +1; + + if (lhs.textSkewX < rhs.textSkewX) return -1; + if (lhs.textSkewX > rhs.textSkewX) return +1; + + if (lhs.textScaleX < rhs.textScaleX) return -1; + if (lhs.textScaleX > rhs.textScaleX) return +1; + + deltaInt = lhs.flags - rhs.flags; + if (deltaInt != 0) return (deltaInt); + + deltaInt = lhs.hinting - rhs.hinting; + if (deltaInt != 0) return (deltaInt); + + deltaInt = lhs.dirFlags - rhs.dirFlags; + if (deltaInt) return (deltaInt); + + return memcmp(lhs.getText(), rhs.getText(), lhs.count * sizeof(UChar)); } void TextLayoutCacheKey::internalTextCopy() { diff --git a/core/jni/android/graphics/TextLayoutCache.h b/core/jni/android/graphics/TextLayoutCache.h index 35dd6fd..6dda1e5 100644 --- a/core/jni/android/graphics/TextLayoutCache.h +++ b/core/jni/android/graphics/TextLayoutCache.h @@ -72,8 +72,6 @@ public: TextLayoutCacheKey(const TextLayoutCacheKey& other); - bool operator<(const TextLayoutCacheKey& rhs) const; - /** * We need to copy the text when we insert the key into the cache itself. * We don't need to copy the text when we are only comparing keys. @@ -85,6 +83,8 @@ public: */ size_t getSize(); + static int compare(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs); + private: const UChar* text; // if text is NULL, use textCopy String16 textCopy; @@ -97,11 +97,18 @@ private: uint32_t flags; SkPaint::Hinting hinting; - inline const UChar* getText() const { - return text ? text : textCopy.string(); - } + inline const UChar* getText() const { return text ? text : textCopy.string(); } + }; // TextLayoutCacheKey +inline int strictly_order_type(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs) { + return TextLayoutCacheKey::compare(lhs, rhs) < 0; +} + +inline int compare_type(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs) { + return TextLayoutCacheKey::compare(lhs, rhs); +} + /* * TextLayoutCacheValue is the Cache value */ |