Skip to content

Commit 2b2700e

Browse files
committed
Add span.annotator-hl wrappers without jQuery
This funtion accounted for ~1 second of the remaining time in my 5000×3 table test case. With this change it's more like 200ms, which is still not ideal but a lot better. $.wrapAll seems relatively expensive. I suppose it has to do lots of extra work that's not necessary when we know we have exactly one element to wrap at a time.
1 parent 824e6d6 commit 2b2700e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/ui/highlighter.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ function highlightRange(normedRange, cssClass) {
2121
}
2222
var white = /^\s*$/;
2323

24-
var hl = $("<span class='" + cssClass + "'></span>");
25-
2624
// Ignore text nodes that contain only whitespace characters. This prevents
2725
// spans being injected between elements that can only contain a restricted
2826
// subset of nodes such as table rows and lists. This does mean that there
@@ -33,9 +31,11 @@ function highlightRange(normedRange, cssClass) {
3331
for (var i = 0, len = nodes.length; i < len; i++) {
3432
var node = nodes[i];
3533
if (!white.test(node.nodeValue)) {
36-
results.push(
37-
$(node).wrapAll(hl).parent()[0]
38-
);
34+
var hl = document.createElement('span');
35+
hl.className = cssClass;
36+
node.parentNode.replaceChild(hl, node);
37+
hl.appendChild(node);
38+
results.push(hl);
3939
}
4040
}
4141
return results;

0 commit comments

Comments
 (0)