Browse Source

defineProperty is slow, don't use it for fastbuffer

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
17ba821e60
  1. 26
      lib/buffer.js

26
lib/buffer.js

@ -91,12 +91,8 @@ function Buffer (subject, encoding, offset) {
// Are we slicing?
if (typeof offset === 'number') {
this.length = encoding;
Object.defineProperty(this, "parent", { enumerable: false,
value: subject,
writable: false });
Object.defineProperty(this, "offset", { enumerable: false,
value: offset,
writable: false });
this.parent = subject;
this.offset = offset;
} else {
// Find the length
switch (type = typeof subject) {
@ -120,22 +116,14 @@ function Buffer (subject, encoding, offset) {
if (length > Buffer.poolSize) {
// Big buffer, just alloc one.
var parent = new SlowBuffer(subject, encoding);
Object.defineProperty(this, "parent", { enumerable: false,
value: parent,
writable: false });
Object.defineProperty(this, "offset", { enumerable: false,
value: 0,
writable: false });
this.parent = new SlowBuffer(subject, encoding);
this.offset = 0;
} else {
// Small buffer.
if (!pool || pool.length - pool.used < length) allocPool();
Object.defineProperty(this, "parent", { enumerable: false,
value: pool,
writable: false });
Object.defineProperty(this, "offset", { enumerable: false,
value: pool.used,
writable: false });
this.parent = pool;
this.offset = pool.used;
pool.used += length;
// Do we need to write stuff?

Loading…
Cancel
Save