Simplify fast buffer constructor
This commit is contained in:
parent
3e9f636b64
commit
ba2e4a2306
@ -114,7 +114,7 @@ function Buffer (subject, encoding, offset) {
|
|||||||
|
|
||||||
if (this.length > Buffer.poolSize) {
|
if (this.length > Buffer.poolSize) {
|
||||||
// Big buffer, just alloc one.
|
// Big buffer, just alloc one.
|
||||||
this.parent = new SlowBuffer(subject, encoding);
|
this.parent = new SlowBuffer(this.length);
|
||||||
this.offset = 0;
|
this.offset = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -123,19 +123,16 @@ function Buffer (subject, encoding, offset) {
|
|||||||
this.parent = pool;
|
this.parent = pool;
|
||||||
this.offset = pool.used;
|
this.offset = pool.used;
|
||||||
pool.used += this.length;
|
pool.used += this.length;
|
||||||
|
}
|
||||||
|
|
||||||
// Do we need to write stuff?
|
// Assume object is an array
|
||||||
if (type !== 'number') {
|
if (Array.isArray(subject)) {
|
||||||
// Assume object is an array
|
for (var i = 0; i < this.length; i++) {
|
||||||
if (type === 'object') {
|
this.parent[i + this.offset] = subject[i];
|
||||||
for (var i = 0; i < this.length; i++) {
|
|
||||||
this.parent[i + this.offset] = subject[i];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// We are a string
|
|
||||||
this.write(subject, 0, encoding);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else if (type == 'string') {
|
||||||
|
// We are a string
|
||||||
|
this.write(subject, 0, encoding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user