Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typefaces are now cached #221

Closed
wants to merge 1 commit into from
Closed

Conversation

skywall
Copy link

@skywall skywall commented Jul 8, 2015

Critically improves layout loading speed when multiple instances of MaterialEditText with custom typefaces is used.

private static final Hashtable<String, Typeface> FONT_CACHE = new Hashtable<>();

public static Typeface get(String name, AssetManager assets) {
synchronized (FONT_CACHE) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hashtable is already synchronised. Does it need to be sync? the get typeface is executed on the UI thread.. and anyway I would use a weakreference to the typeface..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You`re right in case of synchronization. But I'm quite skeptical about weak references to typefaces. In situation you're moving from one activity to another, the fonts will be (probably/maybe) garbage collected and loaded again. It is expected the font will be changed in whole application if it's changed in EditTexts. After all, It's not a big deal.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you are right about the weakreference but I would prefer to reload it than having it in memory if not used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, lets continue in pull-request #252.

@WonderCsabo WonderCsabo mentioned this pull request Nov 12, 2015
@skywall skywall closed this Nov 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants