Files
zulip/zephyr/static/js/dom_access.js
Waseem Daher b730dc7983 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)
2012-10-16 17:06:36 -04:00

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);
}