Skip to content

Commit ba2e4a2

Browse files
committed
Simplify fast buffer constructor
1 parent 3e9f636 commit ba2e4a2

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

lib/buffer.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function Buffer (subject, encoding, offset) {
114114

115115
if (this.length > Buffer.poolSize) {
116116
// Big buffer, just alloc one.
117-
this.parent = new SlowBuffer(subject, encoding);
117+
this.parent = new SlowBuffer(this.length);
118118
this.offset = 0;
119119

120120
} else {
@@ -123,19 +123,16 @@ function Buffer (subject, encoding, offset) {
123123
this.parent = pool;
124124
this.offset = pool.used;
125125
pool.used += this.length;
126+
}
126127

127-
// Do we need to write stuff?
128-
if (type !== 'number') {
129-
// Assume object is an array
130-
if (type === 'object') {
131-
for (var i = 0; i < this.length; i++) {
132-
this.parent[i + this.offset] = subject[i];
133-
}
134-
} else {
135-
// We are a string
136-
this.write(subject, 0, encoding);
137-
}
128+
// Assume object is an array
129+
if (Array.isArray(subject)) {
130+
for (var i = 0; i < this.length; i++) {
131+
this.parent[i + this.offset] = subject[i];
138132
}
133+
} else if (type == 'string') {
134+
// We are a string
135+
this.write(subject, 0, encoding);
139136
}
140137
}
141138

0 commit comments

Comments
 (0)