mirror of https://github.com/zulip/zulip.git
Very very slight speedup in get_next_visible/get_prev_visible.
In my limited trial, this sped the call up, on average, from 0.507ms to 0.473 ms... so, admittedly, not a lot. I think this is a little conceptually cleaner, though, and it handles the common path with the least work, which I like. (imported from commit c8b827a2e8111fbdd54bcabe05ac36f64523c466)
This commit is contained in:
parent
b730dc7983
commit
433ac07b37
|
@ -1,18 +1,24 @@
|
||||||
// We need to andSelf() because more often than not, the next item
|
// We don't need an andSelf() here because we already know
|
||||||
// *is* a .message_row, so nextUntil returns an empty set (except for
|
// that our next element is *not* a message_row, so this
|
||||||
// when it's in a bookend).
|
// isn't going to end up empty unless we're at the bottom or top.
|
||||||
// (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) {
|
function get_next_visible(message_row) {
|
||||||
if (message_row === undefined)
|
if (message_row === undefined)
|
||||||
return [];
|
return [];
|
||||||
return message_row.nextUntil('.message_row').andSelf().next('.message_row');
|
var row = message_row.next('.message_row');
|
||||||
|
if (row.length !== 0) {
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
return message_row.nextUntil('.message_row').next('.message_row');
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_prev_visible(message_row) {
|
function get_prev_visible(message_row) {
|
||||||
if (message_row === undefined)
|
if (message_row === undefined)
|
||||||
return [];
|
return [];
|
||||||
return message_row.prevUntil('.message_row').andSelf().prev('.message_row');
|
var row = message_row.prev('.message_row');
|
||||||
|
if (row.length !== 0) {
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
return message_row.prevUntil('.message_row').prev('.message_row');
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_first_visible() {
|
function get_first_visible() {
|
||||||
|
|
Loading…
Reference in New Issue