mirror of https://github.com/zulip/zulip.git
Huge speedup in get_next_visible/get_prev_visible.
nextAll/prevAll walks the entire DOM, basically. This code only walks the DOM until we find a new .message_row. This speeds up the average time of a call to this function from about 6.38ms to 0.678ms, in my benchmarking. Admittedly, the whole outer loop here could still use some optimization, if we want to; do we really need to call this 1000 times? (imported from commit 852e2f660a16f8cfd7be35d3271aedb1ac481663)
This commit is contained in:
parent
cada47a981
commit
b730dc7983
|
@ -1,13 +1,18 @@
|
|||
// We need to andSelf() because more often than not, the next item
|
||||
// *is* a .message_row, so nextUntil returns an empty set (except for
|
||||
// when it's in a bookend).
|
||||
// (This could probably be further optimized by handling that case
|
||||
// explicitly first, since it's also the common case.)
|
||||
function get_next_visible(message_row) {
|
||||
if (message_row === undefined)
|
||||
return [];
|
||||
return message_row.nextAll('.message_row').filter(':first');
|
||||
return message_row.nextUntil('.message_row').andSelf().next('.message_row');
|
||||
}
|
||||
|
||||
function get_prev_visible(message_row) {
|
||||
if (message_row === undefined)
|
||||
return [];
|
||||
return message_row.prevAll('.message_row').filter(':first');
|
||||
return message_row.prevUntil('.message_row').andSelf().prev('.message_row');
|
||||
}
|
||||
|
||||
function get_first_visible() {
|
||||
|
|
Loading…
Reference in New Issue