defineProperty is slow, don't use it for fastbuffer
This commit is contained in:
parent
d3fcd1c75a
commit
17ba821e60
@ -91,12 +91,8 @@ function Buffer (subject, encoding, offset) {
|
|||||||
// Are we slicing?
|
// Are we slicing?
|
||||||
if (typeof offset === 'number') {
|
if (typeof offset === 'number') {
|
||||||
this.length = encoding;
|
this.length = encoding;
|
||||||
Object.defineProperty(this, "parent", { enumerable: false,
|
this.parent = subject;
|
||||||
value: subject,
|
this.offset = offset;
|
||||||
writable: false });
|
|
||||||
Object.defineProperty(this, "offset", { enumerable: false,
|
|
||||||
value: offset,
|
|
||||||
writable: false });
|
|
||||||
} else {
|
} else {
|
||||||
// Find the length
|
// Find the length
|
||||||
switch (type = typeof subject) {
|
switch (type = typeof subject) {
|
||||||
@ -120,22 +116,14 @@ function Buffer (subject, encoding, offset) {
|
|||||||
|
|
||||||
if (length > Buffer.poolSize) {
|
if (length > Buffer.poolSize) {
|
||||||
// Big buffer, just alloc one.
|
// Big buffer, just alloc one.
|
||||||
var parent = new SlowBuffer(subject, encoding);
|
this.parent = new SlowBuffer(subject, encoding);
|
||||||
Object.defineProperty(this, "parent", { enumerable: false,
|
this.offset = 0;
|
||||||
value: parent,
|
|
||||||
writable: false });
|
|
||||||
Object.defineProperty(this, "offset", { enumerable: false,
|
|
||||||
value: 0,
|
|
||||||
writable: false });
|
|
||||||
} else {
|
} else {
|
||||||
// Small buffer.
|
// Small buffer.
|
||||||
if (!pool || pool.length - pool.used < length) allocPool();
|
if (!pool || pool.length - pool.used < length) allocPool();
|
||||||
Object.defineProperty(this, "parent", { enumerable: false,
|
this.parent = pool;
|
||||||
value: pool,
|
this.offset = pool.used;
|
||||||
writable: false });
|
|
||||||
Object.defineProperty(this, "offset", { enumerable: false,
|
|
||||||
value: pool.used,
|
|
||||||
writable: false });
|
|
||||||
pool.used += length;
|
pool.used += length;
|
||||||
|
|
||||||
// Do we need to write stuff?
|
// Do we need to write stuff?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user