Skip to content

Commit eb3b750

Browse files
Fabrice Di MeglioAndroid (Google) Code Review
authored andcommitted
Merge "Improve TextLayoutCache performances a bit"
2 parents 7b1c30d + 717060b commit eb3b750

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

core/jni/android/graphics/TextLayoutCache.cpp

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -251,26 +251,32 @@ TextLayoutCacheKey::TextLayoutCacheKey(const TextLayoutCacheKey& other) :
251251
}
252252
}
253253

254-
bool TextLayoutCacheKey::operator<(const TextLayoutCacheKey& rhs) const {
255-
LTE_INT(count) {
256-
LTE_INT(typeface) {
257-
LTE_FLOAT(textSize) {
258-
LTE_FLOAT(textSkewX) {
259-
LTE_FLOAT(textScaleX) {
260-
LTE_INT(flags) {
261-
LTE_INT(hinting) {
262-
LTE_INT(dirFlags) {
263-
return memcmp(getText(), rhs.getText(),
264-
count * sizeof(UChar)) < 0;
265-
}
266-
}
267-
}
268-
}
269-
}
270-
}
271-
}
272-
}
273-
return false;
254+
int TextLayoutCacheKey::compare(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs) {
255+
int deltaInt = lhs.count - rhs.count;
256+
if (deltaInt != 0) return (deltaInt);
257+
258+
if (lhs.typeface < rhs.typeface) return -1;
259+
if (lhs.typeface > rhs.typeface) return +1;
260+
261+
if (lhs.textSize < rhs.textSize) return -1;
262+
if (lhs.textSize > rhs.textSize) return +1;
263+
264+
if (lhs.textSkewX < rhs.textSkewX) return -1;
265+
if (lhs.textSkewX > rhs.textSkewX) return +1;
266+
267+
if (lhs.textScaleX < rhs.textScaleX) return -1;
268+
if (lhs.textScaleX > rhs.textScaleX) return +1;
269+
270+
deltaInt = lhs.flags - rhs.flags;
271+
if (deltaInt != 0) return (deltaInt);
272+
273+
deltaInt = lhs.hinting - rhs.hinting;
274+
if (deltaInt != 0) return (deltaInt);
275+
276+
deltaInt = lhs.dirFlags - rhs.dirFlags;
277+
if (deltaInt) return (deltaInt);
278+
279+
return memcmp(lhs.getText(), rhs.getText(), lhs.count * sizeof(UChar));
274280
}
275281

276282
void TextLayoutCacheKey::internalTextCopy() {

core/jni/android/graphics/TextLayoutCache.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ class TextLayoutCacheKey {
7272

7373
TextLayoutCacheKey(const TextLayoutCacheKey& other);
7474

75-
bool operator<(const TextLayoutCacheKey& rhs) const;
76-
7775
/**
7876
* We need to copy the text when we insert the key into the cache itself.
7977
* We don't need to copy the text when we are only comparing keys.
@@ -85,6 +83,8 @@ class TextLayoutCacheKey {
8583
*/
8684
size_t getSize();
8785

86+
static int compare(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs);
87+
8888
private:
8989
const UChar* text; // if text is NULL, use textCopy
9090
String16 textCopy;
@@ -97,11 +97,18 @@ class TextLayoutCacheKey {
9797
uint32_t flags;
9898
SkPaint::Hinting hinting;
9999

100-
inline const UChar* getText() const {
101-
return text ? text : textCopy.string();
102-
}
100+
inline const UChar* getText() const { return text ? text : textCopy.string(); }
101+
103102
}; // TextLayoutCacheKey
104103

104+
inline int strictly_order_type(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs) {
105+
return TextLayoutCacheKey::compare(lhs, rhs) < 0;
106+
}
107+
108+
inline int compare_type(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs) {
109+
return TextLayoutCacheKey::compare(lhs, rhs);
110+
}
111+
105112
/*
106113
* TextLayoutCacheValue is the Cache value
107114
*/

0 commit comments

Comments
 (0)