Improve message_range's running time

We also now check that start != -1, as that is probably a mistake.

(imported from commit 7065ed40150fda7b373d137129c0944a8fa03fc1)
This commit is contained in:
Zev Benjamin
2013-05-01 20:46:36 -04:00
parent bea819e039
commit 3b6713d545

View File

@@ -206,18 +206,18 @@ function respond_to_message(reply_type) {
'replying_to_message': message});
}
// Returns messages from the given message list in the specified range, inclusive
function message_range(msg_list, start, end) {
// Returns messages from the given message list in the specified range, inclusive
var result = [];
var i;
for (i = start; i <= end; i++) {
if (msg_list.get(i) !== undefined) {
result.push(msg_list.get(i));
}
if (start === -1) {
blueslip.error("message_range given a start of -1");
}
return result;
var all = msg_list.all();
var compare = function (a, b) { return a.id < b; };
var start_idx = util.lower_bound(all, start, compare);
var end_idx = util.lower_bound(all, end, compare);
return all.slice(start_idx, end_idx + 1);
}
function send_queued_flags() {