Skip to content

Commit 5ee370f

Browse files
committed
More Buffer(num) and Buffer(value) replacing
Signed-off-by: Сковорода Никита Андреевич <chalkerx@gmail.com>
1 parent df41876 commit 5ee370f

5 files changed

Lines changed: 13 additions & 13 deletions

File tree

benchmark/buffers/buffer-creation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function main(conf) {
4949
case 'buffer()':
5050
bench.start();
5151
for (let i = 0; i < n * 1024; i++) {
52-
Buffer(len);
52+
Buffer.allocUnsafe(len);
5353
}
5454
bench.end(n);
5555
break;

test/parallel/test-buffer-fill.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const assert = require('assert');
55
const os = require('os');
66
const SIZE = 28;
77

8-
const buf1 = Buffer(SIZE);
9-
const buf2 = Buffer(SIZE);
8+
const buf1 = Buffer.allocUnsafe(SIZE);
9+
const buf2 = Buffer.allocUnsafe(SIZE);
1010

1111

1212
// Default encoding
@@ -49,7 +49,7 @@ testBufs('\u0222aa', 8, 1, 'utf8');
4949
testBufs('a\u0234b\u0235c\u0236', 4, -1, 'utf8');
5050
testBufs('a\u0234b\u0235c\u0236', 4, 1, 'utf8');
5151
testBufs('a\u0234b\u0235c\u0236', 12, 1, 'utf8');
52-
assert.equal(Buffer(1).fill(0).fill('\u0222')[0], 0xc8);
52+
assert.equal(Buffer.allocUnsafe(1).fill(0).fill('\u0222')[0], 0xc8);
5353

5454

5555
// BINARY
@@ -91,7 +91,7 @@ testBufs('\u0222aa', 8, 1, 'ucs2');
9191
testBufs('a\u0234b\u0235c\u0236', 4, -1, 'ucs2');
9292
testBufs('a\u0234b\u0235c\u0236', 4, 1, 'ucs2');
9393
testBufs('a\u0234b\u0235c\u0236', 12, 1, 'ucs2');
94-
assert.equal(Buffer(1).fill('\u0222', 'ucs2')[0],
94+
assert.equal(Buffer.allocUnsafe(1).fill('\u0222', 'ucs2')[0],
9595
os.endianness() === 'LE' ? 0x22 : 0x02);
9696

9797

@@ -140,13 +140,13 @@ testBufs('Yci0Ysi1Y8i2', 12, 1, 'ucs2');
140140

141141

142142
// Buffer
143-
const buf2Fill = Buffer(1).fill(2);
143+
const buf2Fill = Buffer.allocUnsafe(1).fill(2);
144144
assert.deepEqual(genBuffer(4, [buf2Fill]), [2, 2, 2, 2]);
145145
assert.deepEqual(genBuffer(4, [buf2Fill, 1]), [0, 2, 2, 2]);
146146
assert.deepEqual(genBuffer(4, [buf2Fill, 1, 3]), [0, 2, 2, 0]);
147147
assert.deepEqual(genBuffer(4, [buf2Fill, 1, 1]), [0, 0, 0, 0]);
148148
assert.deepEqual(genBuffer(4, [buf2Fill, 1, -1]), [0, 0, 0, 0]);
149-
const hexBufFill = Buffer(2).fill(0).fill('0102', 'hex');
149+
const hexBufFill = Buffer.allocUnsafe(2).fill(0).fill('0102', 'hex');
150150
assert.deepEqual(genBuffer(4, [hexBufFill]), [1, 2, 1, 2]);
151151
assert.deepEqual(genBuffer(4, [hexBufFill, 1]), [0, 1, 2, 1]);
152152
assert.deepEqual(genBuffer(4, [hexBufFill, 1, 3]), [0, 1, 2, 0]);
@@ -166,7 +166,7 @@ assert.throws(() => buf1.fill('a', 0, 0, 'foo'));
166166

167167

168168
function genBuffer(size, args) {
169-
const b = Buffer(size);
169+
const b = Buffer.allocUnsafe(size);
170170
return b.fill(0).fill.apply(b, args);
171171
}
172172

test/parallel/test-net-connect-buffer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ tcp.listen(common.PORT, function() {
7777
dataWritten = true;
7878
assert.ok(connectHappened);
7979
console.error('socket.bytesWritten', socket.bytesWritten);
80-
//assert.equal(socket.bytesWritten, Buffer(a + b).length);
80+
//assert.equal(socket.bytesWritten, Buffer.from(a + b).length);
8181
console.error('data written');
8282
});
8383
console.error('socket.bytesWritten', socket.bytesWritten);

test/parallel/test-stream-unshift-empty-chunk.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require('../common');
33
var assert = require('assert');
44

5-
// This test verifies that stream.unshift(Buffer(0)) or
5+
// This test verifies that stream.unshift(Buffer.alloc(0)) or
66
// stream.unshift('') does not set state.reading=false.
77
var Readable = require('stream').Readable;
88

test/parallel/test-stream2-readable-empty-buffer-no-eof.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ test2();
1010
function test1() {
1111
const r = new Readable();
1212

13-
// should not end when we get a Buffer(0) or '' as the _read result
14-
// that just means that there is *temporarily* no data, but to go
15-
// ahead and try again later.
13+
// should not end when we get a Buffer.alloc(0) or '' as the _read
14+
// result that just means that there is *temporarily* no data, but to
15+
// go ahead and try again later.
1616
//
1717
// note that this is very unusual. it only works for crypto streams
1818
// because the other side of the stream will call read(0) to cycle

0 commit comments

Comments
 (0)