Make within_viewport take the row offset and row height

The .height() and .width() functions are actually pretty expensive
for the number of times we call them.  The callers of within_viewport
already know the offset and height of the row, so we just pass them
in so the values don't have to be recalculated.

(imported from commit d1c077bd87463d695f0bbe337b6a8b04ac2d17ce)
This commit is contained in:
Zev Benjamin 2013-05-07 11:13:55 -04:00 committed by Tim Abbott
parent 02dc15f426
commit 4de79cf723
2 changed files with 10 additions and 5 deletions

View File

@ -419,7 +419,10 @@ MessageList.prototype = {
} }
var selected_row = current_msg_list.selected_row(); var selected_row = current_msg_list.selected_row();
if (within_viewport(rows.last_visible()) && selected_row && (selected_row.length > 0)) { var last_visible = rows.last_visible();
if (within_viewport(last_visible.offset(), last_visible.height())
&& selected_row && (selected_row.length > 0))
{
var viewport_offset = viewport.scrollTop(); var viewport_offset = viewport.scrollTop();
var new_messages_height = 0; var new_messages_height = 0;

View File

@ -67,10 +67,10 @@ $(function () {
}); });
function within_viewport(message_row) { function within_viewport(row_offset, row_height) {
// Returns true if a message is fully within the viewport. // Returns true if a message is fully within the viewport.
var message_top = message_row.offset().top; var message_top = row_offset.top;
var message_bottom = message_top + message_row.height(); var message_bottom = message_top + row_height;
var viewport_top = viewport.scrollTop(); var viewport_top = viewport.scrollTop();
var viewport_bottom = viewport_top + viewport.height(); var viewport_bottom = viewport_top + viewport.height();
return (message_top > viewport_top) && (message_bottom < viewport_bottom); return (message_top > viewport_top) && (message_bottom < viewport_bottom);
@ -408,8 +408,10 @@ function process_visible_unread_messages() {
var visible_messages = candidates.filter(function (idx, message) { var visible_messages = candidates.filter(function (idx, message) {
var row = $(message); var row = $(message);
var row_offset = row.offset();
var row_height = row.height();
// Mark very tall messages as read once we've gotten past them // Mark very tall messages as read once we've gotten past them
return (row.height() > height && row.offset().top > top) || within_viewport(row); return (row_height > height && row_offset.top > top) || within_viewport(row_offset, row_height);
}); });
var mark_as_read = $.map(visible_messages, function(msg) { var mark_as_read = $.map(visible_messages, function(msg) {