-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
buffer: replace SlowBuffer with Buffer.allocUnsafeSlow(size) #5833
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ var common = require('../common'); | |
var assert = require('assert'); | ||
|
||
var Buffer = require('buffer').Buffer; | ||
var SlowBuffer = require('buffer').SlowBuffer; | ||
|
||
// counter to ensure unique value is always copied | ||
var cntr = 0; | ||
|
@@ -428,7 +427,7 @@ for (let i = 0; i < Buffer.byteLength(utf8String); i++) { | |
|
||
{ | ||
// also from a non-pooled instance | ||
const b = new SlowBuffer(5); | ||
const b = Buffer.allocUnsafeSlow(5); | ||
const c = b.slice(0, 4); | ||
const d = c.slice(0, 2); | ||
assert.equal(c.parent, d.parent); | ||
|
@@ -1305,7 +1304,7 @@ assert.throws(function() { | |
|
||
// try to slice a zero length Buffer | ||
// see https://github.com/joyent/node/issues/5881 | ||
SlowBuffer(0).slice(0, 1); | ||
Buffer.alloc(0).slice(0, 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably may not make any difference but this is the only place which doesn't use allocUnsafeSlow There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes no difference. alloc, allocUnsafe, and allocUnsafeSlow all do the same thing when the size is zero. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, just documenting the observation :) |
||
})(); | ||
|
||
// Regression test for #5482: should throw but not assert in C++ land. | ||
|
@@ -1336,7 +1335,7 @@ assert.throws(function() { | |
}, RangeError); | ||
|
||
assert.throws(function() { | ||
SlowBuffer((-1 >>> 0) + 1); | ||
Buffer.allocUnsafeSlow((-1 >>> 0) + 1); | ||
}, RangeError); | ||
|
||
if (common.hasCrypto) { | ||
|
@@ -1435,14 +1434,13 @@ assert.throws(function() { | |
}, regErrorMsg); | ||
|
||
|
||
// Test prototype getters don't throw | ||
assert.equal(Buffer.prototype.parent, undefined); | ||
assert.equal(Buffer.prototype.offset, undefined); | ||
assert.equal(SlowBuffer.prototype.parent, undefined); | ||
assert.equal(SlowBuffer.prototype.offset, undefined); | ||
|
||
|
||
// Test that ParseArrayIndex handles full uint32 | ||
assert.throws(function() { | ||
Buffer.from(new ArrayBuffer(0), -1 >>> 0); | ||
}, /RangeError: 'offset' is out of bounds/); | ||
|
||
// Unpooled buffer (replaces SlowBuffer) | ||
const ubuf = Buffer.allocUnsafeSlow(10); | ||
assert(ubuf); | ||
assert(ubuf.buffer); | ||
assert.equal(ubuf.buffer.byteLength, 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can be stricter here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be but I'm not sure we need to be.