Speed-up JS generator function in Adblock

This commit is contained in:
Paweł Forysiuk 2011-06-06 12:47:19 -04:00 committed by Christian Dywan
parent 5f1cd907ad
commit f46f3f0be0

View file

@ -720,10 +720,7 @@ static gchar*
adblock_prepare_urihider_js (GList* uris) adblock_prepare_urihider_js (GList* uris)
{ {
GList* li = NULL; GList* li = NULL;
gchar* out; GString* js = g_string_new (
gchar* cmd = g_strdup ("");
gchar* tmp;
const char *js =
"(function() {" "(function() {"
"function getElementsByAttribute (strTagName, strAttributeName, arrAttributeValue) {" "function getElementsByAttribute (strTagName, strAttributeName, arrAttributeValue) {"
" var arrElements = document.getElementsByTagName (strTagName);" " var arrElements = document.getElementsByTagName (strTagName);"
@ -749,20 +746,14 @@ adblock_prepare_urihider_js (GList* uris)
" oElements[i].style.height = '0';" " oElements[i].style.height = '0';"
" }" " }"
"};" "};"
"var uris=new Array ();" "var uris=new Array ();");
"%s"
"hideElementBySrc (uris);"
"})();";
for (li = uris; li != NULL; li = g_list_next (li)) for (li = uris; li != NULL; li = g_list_next (li))
{ g_string_append_printf (js, "uris.push ('%s');", (gchar*)li->data);
tmp = g_strdup_printf ("uris.push ('%s');%s", (gchar*)li->data, cmd);
katze_assign (cmd, tmp);
}
out = g_strdup_printf (js, cmd);
g_free (cmd);
return out; g_string_append (js, "hideElementBySrc (uris);})();");
return g_string_free (js, FALSE);
} }
static void static void