Use document fragment for the hint nodes.
authorDaniel Carl <danielcarl@gmx.de>
Mon, 11 Mar 2013 21:20:02 +0000 (22:20 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Mon, 11 Mar 2013 21:20:02 +0000 (22:20 +0100)
The appendChild in the fragment is faster than multiple operation on document.

src/hints.c
src/hints.js

index ff6c799..3b85eaa 100644 (file)
@@ -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;
 
index 91cb8ad..5e8e5b1 100644 (file)
@@ -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 = [];