|
@ -86,7 +86,7 @@ function Buffer (subject, encoding, offset) { |
|
|
return new Buffer(subject, encoding, offset); |
|
|
return new Buffer(subject, encoding, offset); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var length, type; |
|
|
var type; |
|
|
|
|
|
|
|
|
// Are we slicing?
|
|
|
// Are we slicing?
|
|
|
if (typeof offset === 'number') { |
|
|
if (typeof offset === 'number') { |
|
@ -97,40 +97,38 @@ function Buffer (subject, encoding, offset) { |
|
|
// Find the length
|
|
|
// Find the length
|
|
|
switch (type = typeof subject) { |
|
|
switch (type = typeof subject) { |
|
|
case 'number': |
|
|
case 'number': |
|
|
length = subject; |
|
|
this.length = subject; |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case 'string': |
|
|
case 'string': |
|
|
length = Buffer.byteLength(subject, encoding); |
|
|
this.length = Buffer.byteLength(subject, encoding); |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case 'object': // Assume object is an array
|
|
|
case 'object': // Assume object is an array
|
|
|
length = subject.length; |
|
|
this.length = subject.length; |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
default: |
|
|
default: |
|
|
throw new Error("First argument need to be an number, array or string."); |
|
|
throw new Error("First argument need to be an number, array or string."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.length = length; |
|
|
if (this.length > Buffer.poolSize) { |
|
|
|
|
|
|
|
|
if (length > Buffer.poolSize) { |
|
|
|
|
|
// Big buffer, just alloc one.
|
|
|
// Big buffer, just alloc one.
|
|
|
this.parent = new SlowBuffer(subject, encoding); |
|
|
this.parent = new SlowBuffer(subject, encoding); |
|
|
this.offset = 0; |
|
|
this.offset = 0; |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
// Small buffer.
|
|
|
// Small buffer.
|
|
|
if (!pool || pool.length - pool.used < 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 += length; |
|
|
pool.used += this.length; |
|
|
|
|
|
|
|
|
// Do we need to write stuff?
|
|
|
// Do we need to write stuff?
|
|
|
if (type !== 'number') { |
|
|
if (type !== 'number') { |
|
|
// Assume object is an array
|
|
|
// Assume object is an array
|
|
|
if (type === 'object') { |
|
|
if (type === 'object') { |
|
|
for (var i = 0; i < length; i++) { |
|
|
for (var i = 0; i < this.length; i++) { |
|
|
this.parent[i + this.offset] = subject[i]; |
|
|
this.parent[i + this.offset] = subject[i]; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|