From: Daniel Carl Date: Mon, 11 Mar 2013 21:20:02 +0000 (+0100) Subject: Use document fragment for the hint nodes. X-Git-Url: https://git.owens.tech/about.html/about.html/git?a=commitdiff_plain;h=34deb67de9f227191ae0cce66e989247d3ad6644;p=vimb.git Use document fragment for the hint nodes. The appendChild in the fragment is faster than multiple operation on document. --- diff --git a/src/hints.c b/src/hints.c index ff6c799..3b85eaa 100644 --- a/src/hints.c +++ b/src/hints.c @@ -25,7 +25,7 @@ #include "hints.js.h" #define HINT_VAR "VpHint" -#define HINT_FILE NULL +#define HINT_FILE "hints.js" extern const unsigned int MAXIMUM_HINTS; diff --git a/src/hints.js b/src/hints.js index 91cb8ad..5e8e5b1 100644 --- a/src/hints.js +++ b/src/hints.js @@ -34,9 +34,7 @@ VimpHints = function Hints(mode, usage, bg, bgf, fg, style, maxHints) { var scrollX = win.scrollX; var scrollY = win.scrollY; - hCont = doc.createElement("div"); - hCont.id = "hint_container"; - + var fragment = doc.createDocumentFragment(); xpath_expr = _getXpath(inputText); var res = doc.evaluate( @@ -78,7 +76,7 @@ VimpHints = function Hints(mode, usage, bg, bgf, fg, style, maxHints) { text = doc.createTextNode(hintCount + 1); hint.appendChild(text); - hCont.appendChild(hint); + fragment.appendChild(hint); hintCount++; hints.push({ elem: elem, @@ -92,7 +90,11 @@ VimpHints = function Hints(mode, usage, bg, bgf, fg, style, maxHints) { elem.style.color = fg; elem.style.background = bg; } + + hCont = doc.createElement("div"); + hCont.id = "hint_container"; + hCont.appendChild(fragment); doc.documentElement.appendChild(hCont); /* recurse into any iframe or frame element */ @@ -173,10 +175,10 @@ VimpHints = function Hints(mode, usage, bg, bgf, fg, style, maxHints) { } for (var i = 0; i < hints.length; ++i) { var hint = hints[i]; - if (typeof(hint.elem) !== "undefined") { + if (hint.elem) { hint.elem.style.background = hint.background; hint.elem.style.color = hint.foreground; - hint.span.parentNode.removeChild(hint.span); + hCont.removeChild(hint.span); } } hints = [];