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