Permalink
Browse files

Use .slice() to generate array of messages to send to callbacks.

  • Loading branch information...
1 parent 50c1bcb commit 5dc4946f33f946234f4b91d3437248d1760d7629 @scottgonzalez committed Apr 18, 2010
Showing with 7 additions and 6 deletions.
  1. +7 −6 lib/channel.js
View
@@ -46,14 +46,15 @@ extend(Channel.prototype, {
},
query: function(since, callback) {
- // TODO: just use .slice()
- var matching = [];
- for (var i = 0; i < this.messages.length; i++) {
- var message = this.messages[i];
- if (message.timestamp > since) {
- matching.push(message);
+ var matching = [],
+ length = this.messages.length;
+ for (var i = 0; i < length; i++) {
+ if (this.messages[i].timestamp > since) {
+ matching = this.messages.slice(i);
+ break;
}
}
+
if (matching.length) {
callback(matching);
} else {

0 comments on commit 5dc4946

Please sign in to comment.