https://bugzilla.wikimedia.org/show_bug.cgi?id=50836

--- Comment #1 from kipod <[email protected]> ---
the function "load" is also asinine, and can cause a high load:

it has two problems: one of them is using $.inArray() to test whether this
fontface was already loaded: this means linear search on the array every single
time (that is, for every single html element with either "lang", "style" or
"class" attributes on the page!), and for pages with large number of elements,
this can be significant. whats more, there is no reason not to add the font
family to the list even when it's not found, to save us some work with future
elements with same font family.

even worse, when getCSS() returns "false" (which it does for 99% of the
elemnts, e.g. when fontFamily is sans-serif), we don't mark this font family as
"tested", so when we find the next element with sans-serif, we do all this work
again.

from performance POV, this is atrocious.


here is a better version of load() - 100% untested.

load: function( fontFamily ) {
    if ( this.fonts[fontFamily] ) 
        return this.fonts[fontFamily] != "abnormal"; 
// does the font have "normal" face?

    var styleString = this.getCSS( fontFamily, 'normal' );
    if ( styleString ) {
        injectCSS( styleString );
        this.fonts[fontFamily] = true;
        return true;
    }
    // Font does not have "normal" face.
    this.fonts[fontFamily] = "abnormal";
    return false;
}


note that "this.fonts" here is an object rather than an array (to save the
linear searches), so it should be initialized to  {} rather than [].

peace.

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are on the CC list for the bug.
_______________________________________________
Wikibugs-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to