Slight filter performance and memory improvement.

This commit is contained in:
Nicolas Stepien 2012-03-03 03:41:56 +01:00
parent ad2e396d04
commit 35abc22d5c
2 changed files with 69 additions and 54 deletions

View File

@ -575,39 +575,21 @@
if (Object.keys(this.filters).length) return g.callbacks.push(this.node);
},
createFilter: function(regexp, op, hl, top) {
return function(post, value) {
var el, firstThread, isOP, thisThread;
el = post.el, isOP = post.isOP;
var test;
test = typeof regexp === 'string' ? function(value) {
return regexp === value;
} : function(value) {
return regexp.test(value);
};
return function(value, isOP) {
if (isOP && op === 'no' || !isOP && op === 'only') return false;
if (typeof regexp === 'string') {
if (regexp !== value) return false;
} else if (!regexp.test(value)) {
return false;
}
if (hl) {
if (isOP) {
$.addClass(el, hl);
} else {
$.addClass(el.parentNode, hl);
}
if (isOP && top && !g.REPLY) {
thisThread = el.parentNode;
if (firstThread = $('div[class=op]')) {
$.before(firstThread.parentNode, [thisThread, thisThread.nextElementSibling]);
}
}
return false;
}
if (isOP) {
if (!g.REPLY) threadHiding.hideHide(el.parentNode);
} else {
replyHiding.hideHide(el);
}
if (!test(value)) return false;
if (hl) return [hl, top];
return true;
};
},
node: function(post) {
var Filter, key, value, _i, _len, _ref;
var Filter, el, firstThread, isOP, key, result, thisThread, value, _i, _len, _ref;
if (post.isInlined) return;
for (key in filter.filters) {
value = filter[key](post);
@ -615,7 +597,31 @@
_ref = filter.filters[key];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
Filter = _ref[_i];
if (Filter(post, value)) return;
if (!(result = Filter(value, isOP))) continue;
isOP = post.isOP, el = post.el;
if (result === true) {
if (isOP) {
if (!g.REPLY) {
threadHiding.hideHide(post.el.parentNode);
} else {
continue;
}
} else {
replyHiding.hideHide(post.el);
}
return;
}
if (isOP) {
$.addClass(el, result[0]);
} else {
$.addClass(el.parentNode, result[0]);
}
if (isOP && result[1] && !g.REPLY) {
thisThread = el.parentNode;
if (firstThread = $('div[class=op]')) {
$.before(firstThread.parentNode, [thisThread, thisThread.nextElementSibling]);
}
}
}
}
},

View File

@ -499,34 +499,19 @@ filter =
g.callbacks.push @node
createFilter: (regexp, op, hl, top) ->
(post, value) ->
{el, isOP} = post
if isOP and op is 'no' or !isOP and op is 'only'
return false
test =
if typeof regexp is 'string'
# MD5 checking
if regexp isnt value
return false
else unless regexp.test value
(value) -> regexp is value
else
(value) -> regexp.test value
(value, isOP) ->
if isOP and op is 'no' or !isOP and op is 'only'
return false
unless test value
return false
if hl
if isOP
$.addClass el, hl
else
$.addClass el.parentNode, hl
if isOP and top and not g.REPLY
# Put the highlighted OPs' threads on top of the board pages...
thisThread = el.parentNode
# ...before the first non highlighted thread.
if firstThread = $ 'div[class=op]'
$.before firstThread.parentNode, [thisThread, thisThread.nextElementSibling]
# Continue the filter lookup to add more classes or hide it.
return false
if isOP
unless g.REPLY
threadHiding.hideHide el.parentNode
else
replyHiding.hideHide el
return [hl, top]
true
node: (post) ->
@ -537,9 +522,33 @@ filter =
# Continue if there's nothing to filter (no tripcode for example).
continue
for Filter in filter.filters[key]
if Filter post, value
unless result = Filter value, isOP
continue
{isOP, el} = post
# Hide
if result is true
if isOP
unless g.REPLY
threadHiding.hideHide post.el.parentNode
else
continue
else
replyHiding.hideHide post.el
return
# Highlight
if isOP
$.addClass el, result[0]
else
$.addClass el.parentNode, result[0]
if isOP and result[1] and not g.REPLY
# Put the highlighted OPs' threads on top of the board pages...
thisThread = el.parentNode
# ...before the first non highlighted thread.
if firstThread = $ 'div[class=op]'
$.before firstThread.parentNode, [thisThread, thisThread.nextElementSibling]
name: (post) ->
name = if post.isOP then $ '.postername', post.el else $ '.commentpostername', post.el
name.textContent