mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 07:23:22 +00:00
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)
35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
// 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.nextUntil('.message_row').andSelf().next('.message_row');
|
|
}
|
|
|
|
function get_prev_visible(message_row) {
|
|
if (message_row === undefined)
|
|
return [];
|
|
return message_row.prevUntil('.message_row').andSelf().prev('.message_row');
|
|
}
|
|
|
|
function get_first_visible() {
|
|
return $('.focused_table .message_row:first');
|
|
}
|
|
|
|
function get_last_visible() {
|
|
return $('.focused_table .message_row:last');
|
|
}
|
|
|
|
function get_id(message_row) {
|
|
return message_row.attr('zid');
|
|
}
|
|
|
|
function get_message_row(message_id, table_name) {
|
|
if (table_name === undefined)
|
|
table_name = (narrowed ? 'zfilt' : 'zhome');
|
|
return $('#' + table_name + message_id);
|
|
}
|