From a4131d64dff457b5c18da460d2a140318250a95f Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Wed, 7 Nov 2007 11:53:26 +0000 Subject: [PATCH] merge faster replace() based v.util.escapeHTML --- content/util.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/content/util.js b/content/util.js index 2eab352b..7f45e386 100644 --- a/content/util.js +++ b/content/util.js @@ -29,9 +29,13 @@ the terms of any one of the MPL, the GPL or the LGPL. vimperator.util = { escapeHTML: function(str) { - var e = window.content.document.createElement("div"); - e.appendChild(window.content.document.createTextNode(str)); - return e.innerHTML; + // XXX: the following code is _much_ slower than a simple .replace() + // :history display went down from 2 to 1 second after changing + // + // var e = window.content.document.createElement("div"); + // e.appendChild(window.content.document.createTextNode(str)); + // return e.innerHTML; + return str.replace("&", "&", "g").replace("<", "<", "g").replace(">", ">", "g"); }, // TODO: use :highlight color groups @@ -81,7 +85,7 @@ vimperator.util = { { if (force || /^[a-zA-Z]+:\/\/.*\//.test(str)) return "" + vimperator.util.escapeHTML(str) + ""; - else + else return str; },