GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — buffer: add .from(), .alloc() and .allocUnsafe() · rbs392/node@85ab4a5

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • benchmark
    • buffers
      • buffer-base64-decode.js
      • buffer-base64-encode.js
      • buffer-bytelength.js
      • buffer-compare.js
      • buffer-creation.js
      • buffer-indexof.js
      • buffer-slice.js
      • buffer-tostring.js
      • buffer_zero.js
    • crypto
      • aes-gcm-throughput.js
      • cipher-stream.js
      • hash-stream-creation.js
      • hash-stream-throughput.js
      • rsa-encrypt-decrypt-throughput.js
      • rsa-sign-verify-throughput.js
    • dgram
      • array-vs-concat.js
      • multi-buffer.js
      • offset-length.js
      • single-buffer.js
    • fs-write-stream-throughput.js
    • fs
      • read-stream-throughput.js
      • readfile.js
      • write-stream-throughput.js
    • http_simple.js
    • http_simple_auto.js
    • http
      • bench-parser.js
      • chunked.js
      • client-request-body.js
      • end-vs-write-end.js
    • net
      • net-c2s-cork.js
      • net-c2s.js
      • net-pipe.js
      • net-s2c.js
      • tcp-raw-c2s.js
      • tcp-raw-pipe.js
      • tcp-raw-s2c.js
    • string_decoder
      • string-decoder.js
    • tls
      • throughput.js
  • doc
    • api
      • buffer.markdown
    • node.1
  • lib
    • _debugger.js
    • _http_client.js
    • _http_outgoing.js
    • _stream_readable.js
    • _stream_writable.js
    • _tls_legacy.js
    • _tls_wrap.js
    • assert.js
    • buffer.js
    • child_process.js
    • crypto.js
    • dgram.js
    • fs.js
    • internal
      • v8_prof_polyfill.js
    • net.js
    • querystring.js
    • string_decoder.js
    • tls.js
    • zlib.js
  • src
    • node.cc
    • node_buffer.cc
    • node_buffer.h
  • test
    • disabled
      • test-debug-brk-file.js
      • test-dgram-send-error.js
      • test-fs-largefile.js
      • test-sendfd.js
    • fixtures
      • GH-892-request.js
      • print-chars-from-buffer.js
    • internet
      • test-dgram-broadcast-multi-process.js
      • test-dgram-multicast-multi-process.js
      • test-dgram-send-cb-quelches-error.js
    • parallel
      • test-async-wrap-check-providers.js
      • test-buffer-alloc.js
      • test-buffer-arraybuffer.js
      • test-buffer-ascii.js
      • test-buffer-bytelength.js
      • test-buffer-concat.js
      • test-buffer-fakes.js
      • test-buffer-fill.js
      • test-buffer-includes.js
      • test-buffer-indexof.js
      • test-buffer-inspect.js
      • test-buffer-iterator.js
      • test-buffer-safe-unsafe.js
      • test-buffer-slow.js
      • test-buffer-zero-fill-cli.js
      • test-buffer-zero-fill-reset.js
      • test-buffer.js
      • test-child-process-fork-dgram.js
      • test-child-process-spawnsync-input.js
      • test-child-process-spawnsync-maxbuf.js
      • test-child-process-stdio-big-write-end.js
      • test-cluster-dgram-1.js
      • test-cluster-dgram-2.js
      • test-crypto-authenticated.js
      • test-crypto-binary-default.js
      • test-crypto-cipher-decipher.js
      • test-crypto-cipheriv-decipheriv.js
      • test-crypto-dh-odd-key.js
      • test-crypto-dh.js
      • test-crypto-from-binary.js
      • test-crypto-hash.js
      • test-crypto-hmac.js
      • test-crypto-padding-aes256.js
      • test-crypto-rsa-dsa.js
      • test-crypto-stream.js
      • test-dgram-bytes-length.js
      • test-dgram-close-is-not-callback.js
      • test-dgram-close.js
      • test-dgram-empty-packet.js
      • test-dgram-exclusive-implicit-bind.js
      • test-dgram-implicit-bind.js
      • test-dgram-msgsize.js
      • test-dgram-oob-buffer.js
      • test-dgram-send-bad-arguments.js
      • test-dgram-send-callback-buffer-length.js
      • test-dgram-send-callback-buffer.js
      • test-dgram-send-callback-multi-buffer.js
      • test-dgram-send-default-host.js
      • test-dgram-send-empty-buffer.js
      • test-file-write-stream3.js
      • test-fs-append-file-sync.js
      • test-fs-append-file.js
      • test-fs-read-buffer-tostring-fail.js
      • test-fs-read-buffer-zero-length.js
      • test-fs-read-buffer.js
      • test-fs-read-stream-encoding.js
      • test-fs-readfile-tostring-fail.js
      • test-fs-readfile-unlink.js
      • test-fs-sir-writes-alot.js
      • test-fs-truncate.js
      • test-fs-write-buffer.js
      • test-fs-write-file-buffer.js
      • test-fs-write-file.js
      • test-fs-write-no-fd.js
      • test-fs-write-stream-encoding.js
      • test-fs-write-stream-err.js
      • test-fs-write-sync.js
      • test-http-buffer-sanity.js
      • test-http-byteswritten.js
      • test-http-client-upload-buf.js
      • test-http-outgoing-finish.js
      • test-http-parser-bad-ref.js
      • test-http-parser.js
      • test-http-pipeline-flood.js
      • test-http-pipeline-regr-3332.js
      • test-http-pipeline-regr-3508.js
      • test-http-regr-gh-2821.js
      • test-http-res-write-end-dont-take-array.js
      • test-http-write-callbacks.js
      • test-https-drain.js
      • test-https-resume-after-renew.js
      • test-https-truncate.js
      • test-net-connect-buffer.js
      • test-net-error-twice.js
      • test-net-stream.js
      • test-net-write-slow.js
      • test-readline-interface.js
      • test-regress-GH-io-1811.js
      • test-stream-big-packet.js
      • test-stream-pipe-cleanup-pause.js
      • test-stream-readable-event.js
      • test-stream-readable-flow-recursion.js
      • test-stream-transform-constructor-set-methods.js
      • test-stream-transform-split-objectmode.js
      • test-stream-unshift-empty-chunk.js
      • test-stream-unshift-read-race.js
      • test-stream-writable-constructor-set-methods.js
      • test-stream-writev.js
      • test-stream2-base64-single-char-read-end.js
      • test-stream2-compatibility.js
      • test-stream2-finish-pipe.js
      • test-stream2-large-read-stall.js
      • test-stream2-pipe-error-handling.js
      • test-stream2-read-sync-stack.js
      • test-stream2-readable-empty-buffer-no-eof.js
      • test-stream2-readable-from-list.js
      • test-stream2-readable-legacy-drain.js
      • test-stream2-readable-non-empty-end.js
      • test-stream2-readable-wrap.js
      • test-stream2-set-encoding.js
      • test-stream2-transform.js
      • test-stream2-unpipe-leak.js
      • test-stream2-writable.js
      • test-stream3-pause-then-read.js
      • test-string-decoder-end.js
      • test-string-decoder.js
      • test-stringbytes-external-at-max.js
      • test-stringbytes-external.js
      • test-tls-alert-handling.js
      • test-tls-cert-regression.js
      • test-tls-client-destroy-soon.js
      • test-tls-delayed-attach-error.js
      • test-tls-fast-writing.js
      • test-tls-hello-parser-failure.js
      • test-tls-inception.js
      • test-tls-max-send-fragment.js
      • test-tls-ocsp-callback.js
      • test-tls-pause.js
      • test-tty-wrap.js
      • test-util.js
      • test-zlib-dictionary-fail.js
      • test-zlib-dictionary.js
      • test-zlib-flush-drain.js
      • test-zlib-flush.js
      • test-zlib-from-string.js
      • test-zlib-params.js
      • test-zlib-random-byte-pipes.js
      • test-zlib-zero-byte.js
      • test-zlib.js
    • pummel
      • test-https-no-reader.js
      • test-regress-GH-814.js
      • test-regress-GH-814_2.js
      • test-stream-pipe-multi.js
      • test-stream2-basic.js
      • test-tls-server-large-request.js
    • sequential
      • test-buffer-bad-overload.js
      • test-child-process-execsync.js
      • test-net-GH-5504.js
      • test-pipe.js
      • test-regress-GH-1697.js
      • test-stringbytes-external-exceed-max-by-1-ascii.js
      • test-stringbytes-external-exceed-max-by-1-base64.js
      • test-stringbytes-external-exceed-max-by-1-binary.js
      • test-stringbytes-external-exceed-max-by-1-hex.js
      • test-stringbytes-external-exceed-max-by-1-utf8.js
      • test-stringbytes-external-exceed-max-by-2.js
      • test-stringbytes-external-exceed-max.js
      • test-zerolengthbufferbug.js

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎benchmark/buffers/buffer-base64-decode.js‎

Copy file name to clipboardExpand all lines: benchmark/buffers/buffer-base64-decode.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function main(conf) {
88
const s = 'abcd'.repeat(8 << 20);
99
s.match(/./); // Flatten string.
1010
assert.equal(s.length % 4, 0);
11-
const b = Buffer(s.length / 4 * 3);
11+
const b = Buffer.allocUnsafe(s.length / 4 * 3);
1212
b.write(s, 0, s.length, 'base64');
1313
bench.start();
1414
for (var i = 0; i < 32; i += 1) b.base64Write(s, 0, s.length);
Collapse file

‎benchmark/buffers/buffer-base64-encode.js‎

Copy file name to clipboardExpand all lines: benchmark/buffers/buffer-base64-encode.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var bench = common.createBenchmark(main, {});
55

66
function main(conf) {
77
var N = 64 * 1024 * 1024;
8-
var b = Buffer(N);
8+
var b = Buffer.allocUnsafe(N);
99
var s = '';
1010
var i;
1111
for (i = 0; i < 256; ++i) s += String.fromCharCode(i);
Collapse file

‎benchmark/buffers/buffer-bytelength.js‎

Copy file name to clipboardExpand all lines: benchmark/buffers/buffer-bytelength.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function main(conf) {
2828
strings.push(data);
2929
} else if (encoding === 'base64') {
3030
// Base64 strings will be much longer than their UTF8 counterparts
31-
strings.push(new Buffer(data, 'utf8').toString('base64'));
31+
strings.push(Buffer.from(data, 'utf8').toString('base64'));
3232
}
3333
}
3434

Collapse file

‎benchmark/buffers/buffer-compare.js‎

Copy file name to clipboardExpand all lines: benchmark/buffers/buffer-compare.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ var bench = common.createBenchmark(main, {
77
});
88

99
function main(conf) {
10-
var iter = (conf.millions >>> 0) * 1e6;
11-
var size = (conf.size >>> 0);
12-
var b0 = new Buffer(size).fill('a');
13-
var b1 = new Buffer(size).fill('a');
10+
const iter = (conf.millions >>> 0) * 1e6;
11+
const size = (conf.size >>> 0);
12+
const b0 = Buffer.alloc(size, 'a');
13+
const b1 = Buffer.alloc(size, 'a');
1414

1515
b1[size - 1] = 'b'.charCodeAt(0);
1616

Collapse file

‎benchmark/buffers/buffer-creation.js‎

Copy file name to clipboard
+50-11Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,59 @@
11
'use strict';
22
const SlowBuffer = require('buffer').SlowBuffer;
33

4-
var common = require('../common.js');
5-
var bench = common.createBenchmark(main, {
6-
type: ['fast', 'slow'],
7-
len: [10, 1024],
4+
const common = require('../common.js');
5+
const assert = require('assert');
6+
const bench = common.createBenchmark(main, {
7+
type: [
8+
'fast-alloc',
9+
'fast-alloc-fill',
10+
'fast-allocUnsafe',
11+
'slow',
12+
'buffer()'],
13+
len: [10, 1024, 2048, 4096, 8192],
814
n: [1024]
915
});
1016

1117
function main(conf) {
12-
var len = +conf.len;
13-
var n = +conf.n;
14-
var clazz = conf.type === 'fast' ? Buffer : SlowBuffer;
15-
bench.start();
16-
for (var i = 0; i < n * 1024; i++) {
17-
new clazz(len);
18+
const len = +conf.len;
19+
const n = +conf.n;
20+
switch (conf.type) {
21+
case 'fast-alloc':
22+
bench.start();
23+
for (let i = 0; i < n * 1024; i++) {
24+
Buffer.alloc(len);
25+
}
26+
bench.end(n);
27+
break;
28+
case 'fast-alloc-fill':
29+
bench.start();
30+
for (let i = 0; i < n * 1024; i++) {
31+
Buffer.alloc(len, 0);
32+
}
33+
bench.end(n);
34+
break;
35+
case 'fast-allocUnsafe':
36+
bench.start();
37+
for (let i = 0; i < n * 1024; i++) {
38+
Buffer.allocUnsafe(len);
39+
}
40+
bench.end(n);
41+
break;
42+
case 'slow':
43+
bench.start();
44+
for (let i = 0; i < n * 1024; i++) {
45+
SlowBuffer(len);
46+
}
47+
bench.end(n);
48+
break;
49+
case 'buffer()':
50+
bench.start();
51+
for (let i = 0; i < n * 1024; i++) {
52+
Buffer(len);
53+
}
54+
bench.end(n);
55+
break;
56+
default:
57+
assert.fail(null, null, 'Should not get here');
1858
}
19-
bench.end(n);
2059
}
Collapse file

‎benchmark/buffers/buffer-indexof.js‎

Copy file name to clipboardExpand all lines: benchmark/buffers/buffer-indexof.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ function main(conf) {
2727
}
2828

2929
if (encoding === 'ucs2') {
30-
aliceBuffer = new Buffer(aliceBuffer.toString(), encoding);
30+
aliceBuffer = Buffer.from(aliceBuffer.toString(), encoding);
3131
}
3232

3333
if (conf.type === 'buffer') {
34-
search = new Buffer(new Buffer(search).toString(), encoding);
34+
search = Buffer.from(Buffer.from(search).toString(), encoding);
3535
}
3636

3737
bench.start();
Collapse file

‎benchmark/buffers/buffer-slice.js‎

Copy file name to clipboardExpand all lines: benchmark/buffers/buffer-slice.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var bench = common.createBenchmark(main, {
77
n: [1024]
88
});
99

10-
var buf = new Buffer(1024);
10+
var buf = Buffer.allocUnsafe(1024);
1111
var slowBuf = new SlowBuffer(1024);
1212

1313
function main(conf) {
Collapse file

‎benchmark/buffers/buffer-tostring.js‎

Copy file name to clipboardExpand all lines: benchmark/buffers/buffer-tostring.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function main(conf) {
1212
const arg = conf.arg === 'true';
1313
const len = conf.len | 0;
1414
const n = conf.n | 0;
15-
const buf = Buffer(len).fill(42);
15+
const buf = Buffer.alloc(len, 42);
1616

1717
var i;
1818
bench.start();
Collapse file

‎benchmark/buffers/buffer_zero.js‎

Copy file name to clipboardExpand all lines: benchmark/buffers/buffer_zero.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ const bench = common.createBenchmark(main, {
66
n: [1024]
77
});
88

9-
const zero = new Buffer(0);
9+
const zero = Buffer.alloc(0);
1010

1111
function main(conf) {
1212
var n = +conf.n;
1313
bench.start();
1414
for (let i = 0; i < n * 1024; i++) {
15-
new Buffer(zero);
15+
Buffer.from(zero);
1616
}
1717
bench.end(n);
1818
}
Collapse file

‎benchmark/crypto/aes-gcm-throughput.js‎

Copy file name to clipboardExpand all lines: benchmark/crypto/aes-gcm-throughput.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ var bench = common.createBenchmark(main, {
99
});
1010

1111
function main(conf) {
12-
var message = (new Buffer(conf.len)).fill('b');
12+
var message = Buffer.alloc(conf.len, 'b');
1313
var key = crypto.randomBytes(keylen[conf.cipher]);
1414
var iv = crypto.randomBytes(12);
15-
var associate_data = (new Buffer(16)).fill('z');
15+
var associate_data = Buffer.alloc(16, 'z');
1616
bench.start();
1717
AEAD_Bench(conf.cipher, message, associate_data, key, iv, conf.n, conf.len);
1818
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.