classList.contains() is actually really slow.

This commit is contained in:
Nicolas Stepien 2011-11-03 22:51:07 +01:00 committed by James Campos
parent 7e3d360364
commit 61730c93cf
2 changed files with 12 additions and 12 deletions

View File

@ -1835,7 +1835,7 @@
} }
}, },
toggle: function(thread) { toggle: function(thread) {
if (thread.classList.contains('stub') || thread.hidden) { if (/\bstub\b/.test(thread.className) || thread.hidden) {
return threadHiding.show(thread); return threadHiding.show(thread);
} else { } else {
return threadHiding.hide(thread); return threadHiding.hide(thread);
@ -2328,7 +2328,7 @@
quoteBacklink.funk = Function('id', "return'" + format + "'"); quoteBacklink.funk = Function('id', "return'" + format + "'");
return g.callbacks.push(function(root) { return g.callbacks.push(function(root) {
var a, container, el, id, link, qid, quote, quotes, _i, _len, _ref, _results; var a, container, el, id, link, qid, quote, quotes, _i, _len, _ref, _results;
if (root.classList.contains('inline')) { if (/\binline\b/.test(root.className)) {
return; return;
} }
quotes = {}; quotes = {};
@ -2400,7 +2400,7 @@
} }
e.preventDefault(); e.preventDefault();
id = this.hash.slice(1); id = this.hash.slice(1);
if (this.classList.contains('inlined')) { if (/\binlined\b/.test(this.className)) {
quoteInline.rm(this, id); quoteInline.rm(this, id);
} else { } else {
if ($.x("ancestor::*[@id='" + id + "']", this)) { if ($.x("ancestor::*[@id='" + id + "']", this)) {
@ -2443,7 +2443,7 @@
inlined = _ref[_i]; inlined = _ref[_i];
$.x('ancestor::table', $.id(inlined.hash.slice(1))).hidden = false; $.x('ancestor::table', $.id(inlined.hash.slice(1))).hidden = false;
} }
if (q.classList.contains('backlink') && !q.classList.contains('filtered')) { if (/\bbacklink\b/.test(q.className) && !/\bfiltered\b/.test(q.className)) {
$.x('ancestor::table', $.id(id)).hidden = false; $.x('ancestor::table', $.id(id)).hidden = false;
} }
return $.rm(table); return $.rm(table);
@ -2528,7 +2528,7 @@
if (conf['Quote Highlighting']) { if (conf['Quote Highlighting']) {
$.addClass(el, 'qphl'); $.addClass(el, 'qphl');
} }
if (this.classList.contains('backlink')) { if (/\bbacklink\b/.test(this.className)) {
replyID = $.x('preceding::input', this).name; replyID = $.x('preceding::input', this).name;
_ref = $$('.quotelink', qp); _ref = $$('.quotelink', qp);
_results = []; _results = [];
@ -2901,7 +2901,7 @@
} }
form = $('body > form'); form = $('body > form');
form.className = klass; form.className = klass;
if (form.classList.contains('fitheight')) { if (/\bfitheight\b/.test(form.className)) {
$.bind(window, 'resize', imgExpand.resize); $.bind(window, 'resize', imgExpand.resize);
if (!imgExpand.style) { if (!imgExpand.style) {
imgExpand.style = $.addStyle(''); imgExpand.style = $.addStyle('');

View File

@ -1372,7 +1372,7 @@ threadHiding =
threadHiding.show thread threadHiding.show thread
toggle: (thread) -> toggle: (thread) ->
if thread.classList.contains('stub') or thread.hidden if /\bstub\b/.test(thread.className) or thread.hidden
threadHiding.show thread threadHiding.show thread
else else
threadHiding.hide thread threadHiding.hide thread
@ -1756,7 +1756,7 @@ quoteBacklink =
format = conf['backlink'].replace /%id/, "' + id + '" format = conf['backlink'].replace /%id/, "' + id + '"
quoteBacklink.funk = Function 'id', "return'#{format}'" quoteBacklink.funk = Function 'id', "return'#{format}'"
g.callbacks.push (root) -> g.callbacks.push (root) ->
return if root.classList.contains 'inline' return if /\binline\b/.test root.className
quotes = {} quotes = {}
for quote in $$ '.quotelink', root for quote in $$ '.quotelink', root
#don't process >>>/b/ #don't process >>>/b/
@ -1797,7 +1797,7 @@ quoteInline =
return if e.shiftKey or e.altKey or e.ctrlKey or e.button isnt 0 return if e.shiftKey or e.altKey or e.ctrlKey or e.button isnt 0
e.preventDefault() e.preventDefault()
id = @hash[1..] id = @hash[1..]
if @classList.contains 'inlined' if /\binlined\b/.test @className
quoteInline.rm @, id quoteInline.rm @, id
else else
return if $.x("ancestor::*[@id='#{id}']", @) return if $.x("ancestor::*[@id='#{id}']", @)
@ -1828,7 +1828,7 @@ quoteInline =
table = $.x "following::*[@id='i#{id}']", q table = $.x "following::*[@id='i#{id}']", q
for inlined in $$ '.backlink.inlined:not(.filtered)', table for inlined in $$ '.backlink.inlined:not(.filtered)', table
$.x('ancestor::table', $.id inlined.hash[1..]).hidden = false $.x('ancestor::table', $.id inlined.hash[1..]).hidden = false
if q.classList.contains('backlink') and not q.classList.contains 'filtered' if /\bbacklink\b/.test(q.className) and not /\bfiltered\b/.test q.className
$.x('ancestor::table', $.id id).hidden = false $.x('ancestor::table', $.id id).hidden = false
$.rm table $.rm table
@ -1884,7 +1884,7 @@ quotePreview =
if el = $.id id if el = $.id id
qp.innerHTML = el.innerHTML qp.innerHTML = el.innerHTML
$.addClass el, 'qphl' if conf['Quote Highlighting'] $.addClass el, 'qphl' if conf['Quote Highlighting']
if @classList.contains 'backlink' if /\bbacklink\b/.test @className
replyID = $.x('preceding::input', @).name replyID = $.x('preceding::input', @).name
for quote in $$ '.quotelink', qp for quote in $$ '.quotelink', qp
if quote.hash[1..] is replyID if quote.hash[1..] is replyID
@ -2122,7 +2122,7 @@ imgExpand =
klass = 'fitwidth fitheight' klass = 'fitwidth fitheight'
form = $('body > form') form = $('body > form')
form.className = klass form.className = klass
if form.classList.contains 'fitheight' if /\bfitheight\b/.test form.className
$.bind window, 'resize', imgExpand.resize $.bind window, 'resize', imgExpand.resize
unless imgExpand.style unless imgExpand.style
imgExpand.style = $.addStyle '' imgExpand.style = $.addStyle ''