mirror of https://github.com/nodejs/node.git
buffer: zero-length buffers shouldn't be slab-backed
parent
45024e7b75
commit
a6b8f63660
|
@ -199,8 +199,9 @@ function coerce(length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Buffer
|
var zeroBuffer = new SlowBuffer(0);
|
||||||
|
|
||||||
|
// Buffer
|
||||||
function Buffer(subject, encoding, offset) {
|
function Buffer(subject, encoding, offset) {
|
||||||
if (!(this instanceof Buffer)) {
|
if (!(this instanceof Buffer)) {
|
||||||
return new Buffer(subject, encoding, offset);
|
return new Buffer(subject, encoding, offset);
|
||||||
|
@ -242,13 +243,18 @@ function Buffer(subject, encoding, offset) {
|
||||||
this.parent = new SlowBuffer(this.length);
|
this.parent = new SlowBuffer(this.length);
|
||||||
this.offset = 0;
|
this.offset = 0;
|
||||||
|
|
||||||
} else {
|
} else if (this.length > 0) {
|
||||||
// Small buffer.
|
// Small buffer.
|
||||||
if (!pool || pool.length - pool.used < this.length) allocPool();
|
if (!pool || pool.length - pool.used < this.length) allocPool();
|
||||||
this.parent = pool;
|
this.parent = pool;
|
||||||
this.offset = pool.used;
|
this.offset = pool.used;
|
||||||
pool.used += this.length;
|
pool.used += this.length;
|
||||||
if (pool.used & 7) pool.used = (pool.used + 8) & ~7;
|
if (pool.used & 7) pool.used = (pool.used + 8) & ~7;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Zero-length buffer
|
||||||
|
this.parent = zeroBuffer;
|
||||||
|
this.offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Treat array-ish objects as a byte array.
|
// Treat array-ish objects as a byte array.
|
||||||
|
|
Loading…
Reference in New Issue