Merge "Improve TextLayoutCache performances a bit"

This commit is contained in:
Fabrice Di Meglio
2011-10-03 09:56:32 -07:00
committed by Android (Google) Code Review
2 changed files with 38 additions and 25 deletions

View File

@ -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() {

View File

@ -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
*/