Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src,test: drop SlowBuffer #55176

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions benchmark/buffers/buffer-iterate.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict';
const SlowBuffer = require('buffer').SlowBuffer;
const common = require('../common.js');
const assert = require('assert');

const bench = common.createBenchmark(main, {
size: [512, 4096, 16386],
type: ['fast'],
method: ['for', 'forOf', 'iterator'],
n: [1e3],
});
Expand All @@ -16,10 +14,8 @@ const methods = {
'iterator': benchIterator,
};

function main({ size, type, method, n }) {
const buffer = type === 'fast' ?
Buffer.alloc(size) :
SlowBuffer(size).fill(0);
function main({ size, method, n }) {
const buffer = Buffer.alloc(size);

const fn = methods[method];

Expand Down
7 changes: 2 additions & 5 deletions benchmark/buffers/buffer-read-with-byteLength.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ const types = [
];

const bench = common.createBenchmark(main, {
buffer: ['fast'],
type: types,
n: [1e6],
byteLength: [1, 2, 3, 4, 5, 6],
});

function main({ n, buf, type, byteLength }) {
const buff = buf === 'fast' ?
Buffer.alloc(8) :
require('buffer').SlowBuffer(8);
function main({ n, type, byteLength }) {
const buff = Buffer.alloc(8);
const fn = `read${type}`;

buff.writeDoubleLE(0, 0);
Expand Down
7 changes: 2 additions & 5 deletions benchmark/buffers/buffer-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ const types = [
];

const bench = common.createBenchmark(main, {
buffer: ['fast'],
type: types,
n: [1e6],
});

function main({ n, buf, type }) {
const buff = buf === 'fast' ?
Buffer.alloc(8) :
require('buffer').SlowBuffer(8);
function main({ n, type }) {
const buff = Buffer.alloc(8);
const fn = `read${type}`;

buff.writeDoubleLE(0, 0);
Expand Down
6 changes: 2 additions & 4 deletions benchmark/buffers/buffer-slice.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
'use strict';
const common = require('../common.js');
const SlowBuffer = require('buffer').SlowBuffer;

const bench = common.createBenchmark(main, {
type: ['fast', 'slow', 'subarray'],
type: ['slice', 'subarray'],
n: [1e6],
});

const buf = Buffer.allocUnsafe(1024);
const slowBuf = new SlowBuffer(1024);

function main({ n, type }) {
const b = type === 'slow' ? slowBuf : buf;
const b = buf

Check failure on line 12 in benchmark/buffers/buffer-slice.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
const fn = type === 'subarray' ?
() => b.subarray(10, 256) :
() => b.slice(10, 256);
Expand Down
7 changes: 2 additions & 5 deletions benchmark/buffers/buffer-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
];

const bench = common.createBenchmark(main, {
buffer: ['fast'],
type: types,
n: [1e6],
});
Expand Down Expand Up @@ -70,10 +69,8 @@
writeIntBE: 6,
};

function main({ n, buf, type }) {
const buff = buf === 'fast' ?
Buffer.alloc(8) :
require('buffer').SlowBuffer(8);
function main({ n, type }) {
const buff = Buffer.alloc(8)

Check failure on line 73 in benchmark/buffers/buffer-write.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
const fn = `write${type}`;

if (!/\d/.test(fn))
Expand Down
26 changes: 1 addition & 25 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -5326,30 +5326,6 @@ console.log(newBuf.toString('ascii'));
Because the Euro (`€`) sign is not representable in US-ASCII, it is replaced
with `?` in the transcoded `Buffer`.

### Class: `SlowBuffer`

<!-- YAML
deprecated: v6.0.0
-->

> Stability: 0 - Deprecated: Use [`Buffer.allocUnsafeSlow()`][] instead.

See [`Buffer.allocUnsafeSlow()`][]. This was never a class in the sense that
the constructor always returned a `Buffer` instance, rather than a `SlowBuffer`
instance.

#### `new SlowBuffer(size)`

<!-- YAML
deprecated: v6.0.0
-->

> Stability: 0 - Deprecated: Use [`Buffer.allocUnsafeSlow()`][] instead.

* `size` {integer} The desired length of the new `SlowBuffer`.

See [`Buffer.allocUnsafeSlow()`][].

### Buffer constants

<!-- YAML
Expand Down Expand Up @@ -5483,7 +5459,7 @@ added: v5.10.0
Node.js can be started using the `--zero-fill-buffers` command-line option to
cause all newly-allocated `Buffer` instances to be zero-filled upon creation by
default. Without the option, buffers created with [`Buffer.allocUnsafe()`][],
[`Buffer.allocUnsafeSlow()`][], and `new SlowBuffer(size)` are not zero-filled.
and [`Buffer.allocUnsafeSlow()`][] are not zero-filled.
Use of this flag can have a measurable negative impact on performance. Use the
`--zero-fill-buffers` option only when necessary to enforce that newly allocated
`Buffer` instances cannot contain old data that is potentially sensitive.
Expand Down
4 changes: 1 addition & 3 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -2833,8 +2833,7 @@ node --watch --watch-preserve-output test.js
added: v6.0.0
-->

Automatically zero-fills all newly allocated [`Buffer`][] and [`SlowBuffer`][]
instances.
Automatically zero-fills all newly allocated [`Buffer`][] instances.

## Environment variables

Expand Down Expand Up @@ -3580,7 +3579,6 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
[`CRYPTO_secure_malloc_init`]: https://www.openssl.org/docs/man3.0/man3/CRYPTO_secure_malloc_init.html
[`NODE_OPTIONS`]: #node_optionsoptions
[`NO_COLOR`]: https://no-color.org
[`SlowBuffer`]: buffer.md#class-slowbuffer
[`Web Storage`]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API
[`WebSocket`]: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
[`YoungGenerationSizeFromSemiSpaceSize`]: https://chromium.googlesource.com/v8/v8.git/+/refs/tags/10.3.129/src/heap/heap.cc#328
Expand Down
18 changes: 0 additions & 18 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -691,23 +691,6 @@ Type: End-of-Life

`util.error()` has been removed. Please use [`console.error()`][] instead.

### DEP0030: `SlowBuffer`

<!-- YAML
changes:
- version: v6.12.0
pr-url: https://github.com/nodejs/node/pull/10116
description: A deprecation code has been assigned.
- version: v6.0.0
pr-url: https://github.com/nodejs/node/pull/5833
description: Documentation-only deprecation.
-->

Type: Documentation-only

The [`SlowBuffer`][] class is deprecated. Please use
[`Buffer.allocUnsafeSlow(size)`][] instead.

### DEP0031: `ecdh.setPublicKey()`

<!-- YAML
Expand Down Expand Up @@ -3761,7 +3744,6 @@ It is recommended to use the `new` qualifier instead. This applies to all REPL c
[`ReadStream.open()`]: fs.md#class-fsreadstream
[`Server.getConnections()`]: net.md#servergetconnectionscallback
[`Server.listen({fd: <number>})`]: net.md#serverlistenhandle-backlog-callback
[`SlowBuffer`]: buffer.md#class-slowbuffer
[`String.prototype.toWellFormed`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toWellFormed
[`WriteStream.open()`]: fs.md#class-fswritestream
[`assert.CallTracker`]: assert.md#class-assertcalltracker
Expand Down
2 changes: 1 addition & 1 deletion doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ If set to 0 then V8 will choose an appropriate size of the thread pool based on
If the value provided is larger than V8's maximum, then the largest value will be chosen.
.
.It Fl -zero-fill-buffers
Automatically zero-fills all newly allocated Buffer and SlowBuffer instances.
Automatically zero-fills all newly allocated Buffer instances.
.
.It Fl c , Fl -check
Check the script's syntax without executing it.
Expand Down
13 changes: 1 addition & 12 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
TypedArrayPrototypeSet,
TypedArrayPrototypeSlice,
Uint8Array,
Uint8ArrayPrototype,

Check failure on line 54 in lib/buffer.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'Uint8ArrayPrototype' is assigned a value but never used
} = primordials;

const {
Expand Down Expand Up @@ -407,7 +407,7 @@
};

/**
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled
* By default creates a non-zero-filled
* Buffer instance that is not allocated off the pre-initialized pool.
* If `--zero-fill-buffers` is set, will zero-fill the buffer.
*/
Expand All @@ -416,16 +416,6 @@
return createUnsafeBuffer(size);
};

// If --zero-fill-buffers command line argument is set, a zero-filled
// buffer is returned.
function SlowBuffer(size) {
validateNumber(size, 'size', 0, kMaxLength);
return createUnsafeBuffer(size);
}

ObjectSetPrototypeOf(SlowBuffer.prototype, Uint8ArrayPrototype);
ObjectSetPrototypeOf(SlowBuffer, Uint8Array);

function allocate(size) {
if (size <= 0) {
return new FastBuffer();
Expand Down Expand Up @@ -1322,7 +1312,6 @@

module.exports = {
Buffer,
SlowBuffer,
transcode,
isUtf8,
isAscii,
Expand Down
3 changes: 1 addition & 2 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,7 @@ PerProcessOptionsParser::PerProcessOptionsParser(
&PerProcessOptions::v8_thread_pool_size,
kAllowedInEnvvar);
AddOption("--zero-fill-buffers",
"automatically zero-fill all newly allocated Buffer and "
"SlowBuffer instances",
"automatically zero-fill all newly allocated Buffer",
&PerProcessOptions::zero_fill_all_buffers,
kAllowedInEnvvar);
AddOption("--debug-arraybuffer-allocations",
Expand Down
3 changes: 0 additions & 3 deletions test/parallel/test-buffer-alloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const assert = require('assert');
const vm = require('vm');

const {
SlowBuffer,
kMaxLength,
} = require('buffer');

Expand Down Expand Up @@ -1104,8 +1103,6 @@ assert.throws(() => Buffer.from(null), {
// Test prototype getters don't throw
assert.strictEqual(Buffer.prototype.parent, undefined);
assert.strictEqual(Buffer.prototype.offset, undefined);
assert.strictEqual(SlowBuffer.prototype.parent, undefined);
assert.strictEqual(SlowBuffer.prototype.offset, undefined);


{
Expand Down
2 changes: 0 additions & 2 deletions test/parallel/test-buffer-bytelength.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const common = require('../common');
const assert = require('assert');
const SlowBuffer = require('buffer').SlowBuffer;
const vm = require('vm');

[
Expand All @@ -24,7 +23,6 @@ const vm = require('vm');
});

assert(ArrayBuffer.isView(new Buffer(10)));
assert(ArrayBuffer.isView(new SlowBuffer(10)));
assert(ArrayBuffer.isView(Buffer.alloc(10)));
assert(ArrayBuffer.isView(Buffer.allocUnsafe(10)));
assert(ArrayBuffer.isView(Buffer.allocUnsafeSlow(10)));
Expand Down
2 changes: 0 additions & 2 deletions test/parallel/test-buffer-failed-alloc-typed-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require('../common');
const assert = require('assert');
const SlowBuffer = require('buffer').SlowBuffer;

// Test failed or zero-sized Buffer allocations not affecting typed arrays.
// This test exists because of a regression that occurred. Because Buffer
Expand All @@ -15,7 +14,6 @@ const zeroArray = new Uint32Array(10).fill(0);
const sizes = [1e20, 0, 0.1, -1, 'a', undefined, null, NaN];
const allocators = [
Buffer,
SlowBuffer,
Buffer.alloc,
Buffer.allocUnsafe,
Buffer.allocUnsafeSlow,
Expand Down
9 changes: 0 additions & 9 deletions test/parallel/test-buffer-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,20 @@ buffer.INSPECT_MAX_BYTES = 2;
let b = Buffer.allocUnsafe(4);
b.fill('1234');

let s = buffer.SlowBuffer(4);
s.fill('1234');

let expected = '<Buffer 31 32 ... 2 more bytes>';

assert.strictEqual(util.inspect(b), expected);
assert.strictEqual(util.inspect(s), expected);

b = Buffer.allocUnsafe(2);
b.fill('12');

s = buffer.SlowBuffer(2);
s.fill('12');

expected = '<Buffer 31 32>';

assert.strictEqual(util.inspect(b), expected);
assert.strictEqual(util.inspect(s), expected);

buffer.INSPECT_MAX_BYTES = Infinity;

assert.strictEqual(util.inspect(b), expected);
assert.strictEqual(util.inspect(s), expected);

b.inspect = undefined;
b.prop = new Uint8Array(0);
Expand Down
6 changes: 0 additions & 6 deletions test/parallel/test-buffer-no-negative-allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require('../common');
const assert = require('assert');
const { SlowBuffer } = require('buffer');

const msg = {
code: 'ERR_OUT_OF_RANGE',
Expand Down Expand Up @@ -30,8 +29,3 @@ assert.throws(() => Buffer.allocUnsafeSlow(-Buffer.poolSize), msg);
assert.throws(() => Buffer.allocUnsafeSlow(-100), msg);
assert.throws(() => Buffer.allocUnsafeSlow(-1), msg);
assert.throws(() => Buffer.allocUnsafeSlow(NaN), msg);

assert.throws(() => SlowBuffer(-Buffer.poolSize), msg);
assert.throws(() => SlowBuffer(-100), msg);
assert.throws(() => SlowBuffer(-1), msg);
assert.throws(() => SlowBuffer(NaN), msg);
2 changes: 0 additions & 2 deletions test/parallel/test-buffer-over-max-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ require('../common');
const assert = require('assert');

const buffer = require('buffer');
const SlowBuffer = buffer.SlowBuffer;

const kMaxLength = buffer.kMaxLength;
const bufferMaxSizeMsg = {
Expand All @@ -13,7 +12,6 @@ const bufferMaxSizeMsg = {
};

assert.throws(() => Buffer(kMaxLength + 1), bufferMaxSizeMsg);
assert.throws(() => SlowBuffer(kMaxLength + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer.alloc(kMaxLength + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer.allocUnsafe(kMaxLength + 1), bufferMaxSizeMsg);
assert.throws(() => Buffer.allocUnsafeSlow(kMaxLength + 1), bufferMaxSizeMsg);
Loading
Loading