Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 717060b0 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Improve TextLayoutCache performances a bit

- the gain is about 5% and the timing is more stable
- use compare_type() and strictly_order_type()

Change-Id: Iab81869a8ba461ce786a468b6c59b8f34e8db838
parent d4ad7b49
Loading
Loading
Loading
Loading
+26 −20
Original line number Diff line number Diff line
@@ -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() {
+12 −5
Original line number Diff line number Diff line
@@ -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
 */