Cache Typefaces in shadow/flat/CustomStyleSpan

Summary: @public `Typeface` handling in `shadow/flat/CustomStyleSpan` wasn't very efficient. This diff introduces `TypefaceCache` to avoid allocating duplicated `Typeface`s.

Reviewed By: sriramramani

Differential Revision: D2564363
This commit is contained in:
Denis Koroskin
2015-12-07 17:15:54 -08:00
committed by Ahmed El-Helw
parent 5c2f536e9a
commit 007318eb52
2 changed files with 80 additions and 6 deletions

View File

@@ -84,14 +84,10 @@ import android.text.style.MetricAffectingSpan;
return;
}
// TODO: optimize this part (implemented in a followup patch)
if (mFontFamily != null) {
// efficient in API 21+
typeface = Typeface.create(mFontFamily, newStyle);
typeface = TypefaceCache.getTypeface(mFontFamily, newStyle);
} else {
// efficient in API 16+
typeface = Typeface.create(typeface, newStyle);
typeface = TypefaceCache.getTypeface(typeface, newStyle);
}
ds.setTypeface(typeface);