node/test/parallel/test-stream-push-order.js
Brian White 686984696d
stream: improve Readable.read() performance
read() performance is improved most by switching from an array to
a linked list for storing buffered data. However, other changes that
also contribute include: making some hot functions inlinable, faster
read() argument checking, and misc code rearrangement to avoid
unnecessary code execution.

PR-URL: https://github.com/nodejs/node/pull/7077
Reviewed-By: Calvin Metcalf <calvin.metcalf@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2016-06-14 15:15:34 -04:00

32 lines
565 B
JavaScript

'use strict';
require('../common');
var Readable = require('stream').Readable;
var assert = require('assert');
var s = new Readable({
highWaterMark: 20,
encoding: 'ascii'
});
var list = ['1', '2', '3', '4', '5', '6'];
s._read = function(n) {
var one = list.shift();
if (!one) {
s.push(null);
} else {
var two = list.shift();
s.push(one);
s.push(two);
}
};
s.read(0);
// ACTUALLY [1, 3, 5, 6, 4, 2]
process.on('exit', function() {
assert.deepStrictEqual(s._readableState.buffer.join(','), '1,2,3,4,5,6');
console.log('ok');
});