From f46f3f0be0ab648fde87dc4a737e8047a74b3a81 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pawe=C5=82=20Forysiuk?= Date: Mon, 6 Jun 2011 12:47:19 -0400 Subject: [PATCH] Speed-up JS generator function in Adblock --- extensions/adblock.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/extensions/adblock.c b/extensions/adblock.c index 47fb5b52..f271df22 100644 --- a/extensions/adblock.c +++ b/extensions/adblock.c @@ -720,10 +720,7 @@ static gchar* adblock_prepare_urihider_js (GList* uris) { GList* li = NULL; - gchar* out; - gchar* cmd = g_strdup (""); - gchar* tmp; - const char *js = + GString* js = g_string_new ( "(function() {" "function getElementsByAttribute (strTagName, strAttributeName, arrAttributeValue) {" " var arrElements = document.getElementsByTagName (strTagName);" @@ -749,20 +746,14 @@ adblock_prepare_urihider_js (GList* uris) " oElements[i].style.height = '0';" " }" "};" - "var uris=new Array ();" - "%s" - "hideElementBySrc (uris);" - "})();"; + "var uris=new Array ();"); for (li = uris; li != NULL; li = g_list_next (li)) - { - 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); + g_string_append_printf (js, "uris.push ('%s');", (gchar*)li->data); + + g_string_append (js, "hideElementBySrc (uris);})();"); - return out; + return g_string_free (js, FALSE); } static void -- 2.39.5