Skip to content

Commit 647175e

Browse files
committed
buffer: move SlowBuffer to EOL
`SlowBuffer` has been deprecated for many years now. Let's remove it. PR-URL: #58008 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 145c6a2 commit 647175e

23 files changed

+61
-118
lines changed

benchmark/buffers/buffer-iterate.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
const SlowBuffer = require('buffer').SlowBuffer;
2+
const { Buffer } = require('buffer');
33
const common = require('../common.js');
44
const assert = require('assert');
55

@@ -19,7 +19,7 @@ const methods = {
1919
function main({ size, type, method, n }) {
2020
const buffer = type === 'fast' ?
2121
Buffer.alloc(size) :
22-
SlowBuffer(size).fill(0);
22+
Buffer.allocUnsafeSlow(size).fill(0);
2323

2424
const fn = methods[method];
2525

benchmark/buffers/buffer-read-with-byteLength.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3+
const { Buffer } = require('buffer');
34

45
const types = [
56
'IntBE',
@@ -18,7 +19,7 @@ const bench = common.createBenchmark(main, {
1819
function main({ n, buf, type, byteLength }) {
1920
const buff = buf === 'fast' ?
2021
Buffer.alloc(8) :
21-
require('buffer').SlowBuffer(8);
22+
Buffer.allocUnsafeSlow(8);
2223
const fn = `read${type}`;
2324

2425
buff.writeDoubleLE(0, 0);

benchmark/buffers/buffer-read.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3+
const { Buffer } = require('buffer');
34

45
const types = [
56
'BigUInt64LE',
@@ -27,7 +28,7 @@ const bench = common.createBenchmark(main, {
2728
function main({ n, buf, type }) {
2829
const buff = buf === 'fast' ?
2930
Buffer.alloc(8) :
30-
require('buffer').SlowBuffer(8);
31+
Buffer.allocUnsafeSlow(8);
3132
const fn = `read${type}`;
3233

3334
buff.writeDoubleLE(0, 0);

benchmark/buffers/buffer-slice.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
22
const common = require('../common.js');
3-
const SlowBuffer = require('buffer').SlowBuffer;
3+
const { Buffer } = require('buffer');
44

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

1010
const buf = Buffer.allocUnsafe(1024);
11-
const slowBuf = new SlowBuffer(1024);
11+
const slowBuf = Buffer.allocUnsafeSlow(1024);
1212

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

benchmark/buffers/buffer-write.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3-
3+
const { Buffer } = require('buffer');
44
const types = [
55
'BigUInt64LE',
66
'BigUInt64BE',
@@ -73,7 +73,7 @@ const byteLength = {
7373
function main({ n, buf, type }) {
7474
const buff = buf === 'fast' ?
7575
Buffer.alloc(8) :
76-
require('buffer').SlowBuffer(8);
76+
Buffer.allocUnsafeSlow(8);
7777
const fn = `write${type}`;
7878

7979
if (!/\d/.test(fn))

doc/api/buffer.md

+5-27
Original file line numberDiff line numberDiff line change
@@ -5340,28 +5340,6 @@ console.log(newBuf.toString('ascii'));
53405340
Because the Euro (``) sign is not representable in US-ASCII, it is replaced
53415341
with `?` in the transcoded `Buffer`.
53425342

5343-
### Class: `SlowBuffer`
5344-
5345-
<!-- YAML
5346-
deprecated: v6.0.0
5347-
-->
5348-
5349-
> Stability: 0 - Deprecated: Use [`Buffer.allocUnsafeSlow()`][] instead.
5350-
5351-
See [`Buffer.allocUnsafeSlow()`][]. This was never a class in the sense that
5352-
the constructor always returned a `Buffer` instance, rather than a `SlowBuffer`
5353-
instance.
5354-
5355-
#### `new SlowBuffer(size)`
5356-
5357-
<!-- YAML
5358-
deprecated: v6.0.0
5359-
-->
5360-
5361-
* `size` {integer} The desired length of the new `SlowBuffer`.
5362-
5363-
See [`Buffer.allocUnsafeSlow()`][].
5364-
53655343
### Buffer constants
53665344

53675345
<!-- YAML
@@ -5494,11 +5472,11 @@ added: v5.10.0
54945472

54955473
Node.js can be started using the `--zero-fill-buffers` command-line option to
54965474
cause all newly-allocated `Buffer` instances to be zero-filled upon creation by
5497-
default. Without the option, buffers created with [`Buffer.allocUnsafe()`][],
5498-
[`Buffer.allocUnsafeSlow()`][], and `new SlowBuffer(size)` are not zero-filled.
5499-
Use of this flag can have a measurable negative impact on performance. Use the
5500-
`--zero-fill-buffers` option only when necessary to enforce that newly allocated
5501-
`Buffer` instances cannot contain old data that is potentially sensitive.
5475+
default. Without the option, buffers created with [`Buffer.allocUnsafe()`][] and
5476+
[`Buffer.allocUnsafeSlow()`][] are not zero-filled. Use of this flag can have a
5477+
measurable negative impact on performance. Use the `--zero-fill-buffers` option
5478+
only when necessary to enforce that newly allocated `Buffer` instances cannot
5479+
contain old data that is potentially sensitive.
55025480

55035481
```console
55045482
$ node --zero-fill-buffers

doc/api/cli.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -3111,8 +3111,7 @@ node --watch --watch-preserve-output test.js
31113111
added: v6.0.0
31123112
-->
31133113

3114-
Automatically zero-fills all newly allocated [`Buffer`][] and [`SlowBuffer`][]
3115-
instances.
3114+
Automatically zero-fills all newly allocated [`Buffer`][] instances.
31163115

31173116
## Environment variables
31183117

@@ -3887,7 +3886,6 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
38873886
[`ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX`]: errors.md#err_unsupported_typescript_syntax
38883887
[`NODE_OPTIONS`]: #node_optionsoptions
38893888
[`NO_COLOR`]: https://no-color.org
3890-
[`SlowBuffer`]: buffer.md#class-slowbuffer
38913889
[`Web Storage`]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API
38923890
[`WebSocket`]: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
38933891
[`YoungGenerationSizeFromSemiSpaceSize`]: https://chromium.googlesource.com/v8/v8.git/+/refs/tags/10.3.129/src/heap/heap.cc#328

doc/api/deprecations.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,9 @@ Type: End-of-Life
695695

696696
<!-- YAML
697697
changes:
698+
- version: REPLACEME
699+
pr-url: https://github.com/nodejs/node/pull/58008
700+
description: End-of-Life.
698701
- version: REPLACEME
699702
pr-url: https://github.com/nodejs/node/pull/55175
700703
description: Runtime deprecation.
@@ -706,9 +709,9 @@ changes:
706709
description: Documentation-only deprecation.
707710
-->
708711

709-
Type: Runtime
712+
Type: End-of-Life
710713

711-
The [`SlowBuffer`][] class is deprecated. Please use
714+
The `SlowBuffer` class has been removed. Please use
712715
[`Buffer.allocUnsafeSlow(size)`][] instead.
713716

714717
### DEP0031: `ecdh.setPublicKey()`
@@ -3921,7 +3924,6 @@ upon `require('node:module').builtinModules`.
39213924
[`ReadStream.open()`]: fs.md#class-fsreadstream
39223925
[`Server.getConnections()`]: net.md#servergetconnectionscallback
39233926
[`Server.listen({fd: <number>})`]: net.md#serverlistenhandle-backlog-callback
3924-
[`SlowBuffer`]: buffer.md#class-slowbuffer
39253927
[`String.prototype.toWellFormed`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toWellFormed
39263928
[`WriteStream.open()`]: fs.md#class-fswritestream
39273929
[`assert.CallTracker`]: assert.md#class-assertcalltracker

doc/contributing/writing-and-running-benchmarks.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ the code inside the `main` function if it's more than just declaration.
572572
```js
573573
'use strict';
574574
const common = require('../common.js');
575-
const { SlowBuffer } = require('node:buffer');
575+
const { Buffer } = require('node:buffer');
576576

577577
const configs = {
578578
// Number of operations, specified here so they show up in the report.
@@ -603,10 +603,11 @@ function main(conf) {
603603
bench.start();
604604

605605
// Do operations here
606-
const BufferConstructor = conf.type === 'fast' ? Buffer : SlowBuffer;
607606

608607
for (let i = 0; i < conf.n; i++) {
609-
new BufferConstructor(conf.size);
608+
conf.type === 'fast' ?
609+
Buffer.allocUnsafe(conf.size) :
610+
Buffer.allocUnsafeSlow(conf.size);
610611
}
611612

612613
// End the timer, pass in the number of operations

doc/node.1

+1-1
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ If set to 0 then V8 will choose an appropriate size of the thread pool based on
619619
If the value provided is larger than V8's maximum, then the largest value will be chosen.
620620
.
621621
.It Fl -zero-fill-buffers
622-
Automatically zero-fills all newly allocated Buffer and SlowBuffer instances.
622+
Automatically zero-fills all newly allocated Buffer instances.
623623
.
624624
.It Fl c , Fl -check
625625
Check the script's syntax without executing it.

lib/buffer.js

+3-19
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ const {
5252
TypedArrayPrototypeSet,
5353
TypedArrayPrototypeSlice,
5454
Uint8Array,
55-
Uint8ArrayPrototype,
5655
} = primordials;
5756

5857
const {
@@ -89,7 +88,6 @@ const {
8988
kIsEncodingSymbol,
9089
defineLazyProperties,
9190
encodingsMap,
92-
deprecate,
9391
} = require('internal/util');
9492
const {
9593
isAnyArrayBuffer,
@@ -411,25 +409,15 @@ Buffer.allocUnsafe = function allocUnsafe(size) {
411409
};
412410

413411
/**
414-
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled
415-
* Buffer instance that is not allocated off the pre-initialized pool.
416-
* If `--zero-fill-buffers` is set, will zero-fill the buffer.
412+
* By default creates a non-zero-filled Buffer instance that is not allocated
413+
* off the pre-initialized pool. If `--zero-fill-buffers` is set, will zero-fill
414+
* the buffer.
417415
*/
418416
Buffer.allocUnsafeSlow = function allocUnsafeSlow(size) {
419417
validateNumber(size, 'size', 0, kMaxLength);
420418
return createUnsafeBuffer(size);
421419
};
422420

423-
// If --zero-fill-buffers command line argument is set, a zero-filled
424-
// buffer is returned.
425-
function SlowBuffer(size) {
426-
validateNumber(size, 'size', 0, kMaxLength);
427-
return createUnsafeBuffer(size);
428-
}
429-
430-
ObjectSetPrototypeOf(SlowBuffer.prototype, Uint8ArrayPrototype);
431-
ObjectSetPrototypeOf(SlowBuffer, Uint8Array);
432-
433421
function allocate(size) {
434422
if (size <= 0) {
435423
return new FastBuffer();
@@ -1331,10 +1319,6 @@ function isAscii(input) {
13311319

13321320
module.exports = {
13331321
Buffer,
1334-
SlowBuffer: deprecate(
1335-
SlowBuffer,
1336-
'SlowBuffer() is deprecated. Please use Buffer.allocUnsafeSlow()',
1337-
'DEP0030'),
13381322
transcode,
13391323
isUtf8,
13401324
isAscii,

src/node_options.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1052,8 +1052,7 @@ PerProcessOptionsParser::PerProcessOptionsParser(
10521052
&PerProcessOptions::v8_thread_pool_size,
10531053
kAllowedInEnvvar);
10541054
AddOption("--zero-fill-buffers",
1055-
"automatically zero-fill all newly allocated Buffer and "
1056-
"SlowBuffer instances",
1055+
"automatically zero-fill all newly allocated Buffer instances",
10571056
&PerProcessOptions::zero_fill_all_buffers,
10581057
kAllowedInEnvvar);
10591058
AddOption("--debug-arraybuffer-allocations",

test/parallel/test-buffer-alloc.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const assert = require('assert');
55
const vm = require('vm');
66

77
const {
8-
SlowBuffer,
8+
Buffer,
99
kMaxLength,
1010
} = require('buffer');
1111

@@ -1104,9 +1104,6 @@ assert.throws(() => Buffer.from(null), {
11041104
// Test prototype getters don't throw
11051105
assert.strictEqual(Buffer.prototype.parent, undefined);
11061106
assert.strictEqual(Buffer.prototype.offset, undefined);
1107-
assert.strictEqual(SlowBuffer.prototype.parent, undefined);
1108-
assert.strictEqual(SlowBuffer.prototype.offset, undefined);
1109-
11101107

11111108
{
11121109
// Test that large negative Buffer length inputs don't affect the pool offset.
@@ -1139,7 +1136,7 @@ assert.throws(() => {
11391136
a.copy(b, 0, 0x100000000, 0x100000001);
11401137
}, outOfRangeError);
11411138

1142-
// Unpooled buffer (replaces SlowBuffer)
1139+
// Unpooled buffer
11431140
{
11441141
const ubuf = Buffer.allocUnsafeSlow(10);
11451142
assert(ubuf);

test/parallel/test-buffer-bytelength.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const common = require('../common');
44
const assert = require('assert');
5-
const SlowBuffer = require('buffer').SlowBuffer;
5+
const { Buffer } = require('buffer');
66
const vm = require('vm');
77

88
[
@@ -24,7 +24,6 @@ const vm = require('vm');
2424
});
2525

2626
assert(ArrayBuffer.isView(new Buffer(10)));
27-
assert(ArrayBuffer.isView(new SlowBuffer(10)));
2827
assert(ArrayBuffer.isView(Buffer.alloc(10)));
2928
assert(ArrayBuffer.isView(Buffer.allocUnsafe(10)));
3029
assert(ArrayBuffer.isView(Buffer.allocUnsafeSlow(10)));

test/parallel/test-buffer-failed-alloc-typed-arrays.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require('../common');
44
const assert = require('assert');
5-
const SlowBuffer = require('buffer').SlowBuffer;
5+
const { Buffer } = require('buffer');
66

77
// Test failed or zero-sized Buffer allocations not affecting typed arrays.
88
// This test exists because of a regression that occurred. Because Buffer
@@ -15,7 +15,6 @@ const zeroArray = new Uint32Array(10).fill(0);
1515
const sizes = [1e20, 0, 0.1, -1, 'a', undefined, null, NaN];
1616
const allocators = [
1717
Buffer,
18-
SlowBuffer,
1918
Buffer.alloc,
2019
Buffer.allocUnsafe,
2120
Buffer.allocUnsafeSlow,

test/parallel/test-buffer-inspect.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ buffer.INSPECT_MAX_BYTES = 2;
3030
let b = Buffer.allocUnsafe(4);
3131
b.fill('1234');
3232

33-
let s = buffer.SlowBuffer(4);
33+
let s = Buffer.allocUnsafeSlow(4);
3434
s.fill('1234');
3535

3636
let expected = '<Buffer 31 32 ... 2 more bytes>';
@@ -41,7 +41,7 @@ assert.strictEqual(util.inspect(s), expected);
4141
b = Buffer.allocUnsafe(2);
4242
b.fill('12');
4343

44-
s = buffer.SlowBuffer(2);
44+
s = Buffer.allocUnsafeSlow(2);
4545
s.fill('12');
4646

4747
expected = '<Buffer 31 32>';

test/parallel/test-buffer-no-negative-allocation.js

-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
require('../common');
44
const assert = require('assert');
5-
const { SlowBuffer } = require('buffer');
65

76
const msg = {
87
code: 'ERR_OUT_OF_RANGE',
@@ -30,8 +29,3 @@ assert.throws(() => Buffer.allocUnsafeSlow(-Buffer.poolSize), msg);
3029
assert.throws(() => Buffer.allocUnsafeSlow(-100), msg);
3130
assert.throws(() => Buffer.allocUnsafeSlow(-1), msg);
3231
assert.throws(() => Buffer.allocUnsafeSlow(NaN), msg);
33-
34-
assert.throws(() => SlowBuffer(-Buffer.poolSize), msg);
35-
assert.throws(() => SlowBuffer(-100), msg);
36-
assert.throws(() => SlowBuffer(-1), msg);
37-
assert.throws(() => SlowBuffer(NaN), msg);

test/parallel/test-buffer-over-max-length.js

-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ require('../common');
44
const assert = require('assert');
55

66
const buffer = require('buffer');
7-
const SlowBuffer = buffer.SlowBuffer;
87

98
const kMaxLength = buffer.kMaxLength;
109
const bufferMaxSizeMsg = {
@@ -13,7 +12,6 @@ const bufferMaxSizeMsg = {
1312
};
1413

1514
assert.throws(() => Buffer(kMaxLength + 1), bufferMaxSizeMsg);
16-
assert.throws(() => SlowBuffer(kMaxLength + 1), bufferMaxSizeMsg);
1715
assert.throws(() => Buffer.alloc(kMaxLength + 1), bufferMaxSizeMsg);
1816
assert.throws(() => Buffer.allocUnsafe(kMaxLength + 1), bufferMaxSizeMsg);
1917
assert.throws(() => Buffer.allocUnsafeSlow(kMaxLength + 1), bufferMaxSizeMsg);

0 commit comments

Comments
 (0)