Main.preParser performance optimization. Use getElementsByClassName for "quotelink" and "backlink".

querySelectorAll was slower, and Array.prototype.slice was an overkill.
This speeds up the preParser by about 35%.
This commit is contained in:
Nicolas Stepien 2012-03-06 23:21:27 +01:00
parent 14d48f59b2
commit 7ab4487020
2 changed files with 24 additions and 10 deletions

View File

@ -3163,14 +3163,19 @@
return g.callbacks.push(this.node);
},
node: function(post) {
var quote, _i, _len, _ref;
_ref = post.quotes.concat(post.backlinks);
var quote, _i, _j, _len, _len2, _ref, _ref2;
_ref = post.quotes;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
quote = _ref[_i];
if (!quote.hash) continue;
quote.removeAttribute('onclick');
$.on(quote, 'click', QuoteInline.toggle);
}
_ref2 = post.backlinks;
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
quote = _ref2[_j];
$.on(quote, 'click', QuoteInline.toggle);
}
},
toggle: function(e) {
var id;
@ -3289,12 +3294,17 @@
return g.callbacks.push(this.node);
},
node: function(post) {
var quote, _i, _len, _ref;
_ref = post.quotes.concat(post.backlinks);
var quote, _i, _j, _len, _len2, _ref, _ref2;
_ref = post.quotes;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
quote = _ref[_i];
if (quote.hash) $.on(quote, 'mouseover', QuotePreview.mouseover);
}
_ref2 = post.backlinks;
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
quote = _ref2[_j];
$.on(quote, 'mouseover', QuotePreview.mouseover);
}
},
mouseover: function(e) {
var el, id, qp, quote, replyID, threadID, _i, _len, _ref;
@ -3988,8 +3998,8 @@
isInlined: /\binline\b/.test(klass),
filesize: $('.filesize', node),
img: $('img[md5]', node),
quotes: $$('.quotelink', node),
backlinks: $$('.backlink', node)
quotes: node.getElementsByClassName('quotelink'),
backlinks: node.getElementsByClassName('backlink')
};
},
node: function(nodes, notify) {

View File

@ -2620,10 +2620,12 @@ QuoteInline =
init: ->
g.callbacks.push @node
node: (post) ->
for quote in post.quotes.concat post.backlinks
for quote in post.quotes
continue unless quote.hash
quote.removeAttribute 'onclick'
$.on quote, 'click', QuoteInline.toggle
for quote in post.backlinks
$.on quote, 'click', QuoteInline.toggle
return
toggle: (e) ->
return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0
@ -2712,8 +2714,10 @@ QuotePreview =
init: ->
g.callbacks.push @node
node: (post) ->
for quote in post.quotes.concat post.backlinks
for quote in post.quotes
$.on quote, 'mouseover', QuotePreview.mouseover if quote.hash
for quote in post.backlinks
$.on quote, 'mouseover', QuotePreview.mouseover
return
mouseover: (e) ->
return if /\binlined\b/.test @className
@ -3324,8 +3328,8 @@ Main =
isInlined: /\binline\b/.test klass
filesize: $ '.filesize', node
img: $ 'img[md5]', node
quotes: $$ '.quotelink', node
backlinks: $$ '.backlink', node
quotes: node.getElementsByClassName 'quotelink'
backlinks: node.getElementsByClassName 'backlink'
node: (nodes, notify) ->
for callback in g.callbacks
try