forked from redis/node-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JavaScript parser passes all tests when returning strings.
JS is still way too slow for large mb replies. Hiredis is fast for strings of large replies, but slow for buffers.
- Loading branch information
Showing
3 changed files
with
84 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
function to_array(args) { | ||
var len = args.length, | ||
arr = new Array(len), i; | ||
|
||
for (i = 0; i < len; i += 1) { | ||
arr[i] = args[i]; | ||
} | ||
|
||
return arr; | ||
} | ||
|
||
// Queue class adapted from Tim Caswell's pattern library | ||
// http://github.com/creationix/pattern/blob/master/lib/pattern/queue.js | ||
|
||
var Queue = function () { | ||
this.tail = []; | ||
this.head = to_array(arguments); | ||
this.offset = 0; | ||
}; | ||
|
||
Queue.prototype.shift = function () { | ||
if (this.offset === this.head.length) { | ||
var tmp = this.head; | ||
tmp.length = 0; | ||
this.head = this.tail; | ||
this.tail = tmp; | ||
this.offset = 0; | ||
if (this.head.length === 0) { | ||
return; | ||
} | ||
} | ||
return this.head[this.offset++]; // sorry, JSLint | ||
}; | ||
|
||
Queue.prototype.push = function (item) { | ||
return this.tail.push(item); | ||
}; | ||
|
||
Queue.prototype.forEach = function (fn, thisv) { | ||
var array = this.head.slice(this.offset), i, il; | ||
|
||
array.push.apply(array, this.tail); | ||
|
||
if (thisv) { | ||
for (i = 0, il = array.length; i < il; i += 1) { | ||
fn.call(thisv, array[i], i, array); | ||
} | ||
} else { | ||
for (i = 0, il = array.length; i < il; i += 1) { | ||
fn(array[i], i, array); | ||
} | ||
} | ||
|
||
return array; | ||
}; | ||
|
||
Object.defineProperty(Queue.prototype, 'length', { | ||
get: function () { | ||
return this.head.length - this.offset + this.tail.length; | ||
} | ||
}); | ||
|
||
exports.Queue = Queue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters