Skip to content

Commit 5c80370

Browse files
authored
Merge pull request #40 from shimaore/proper-alloc
use proper alloc at all times
2 parents 1480064 + 7a38415 commit 5c80370

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

jsonparse.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,16 @@ var TAB = "\t".charCodeAt(0);
5151

5252
var STRING_BUFFER_SIZE = 64 * 1024;
5353

54+
function alloc(size) {
55+
return Buffer.alloc ? Buffer.alloc(size) : new Buffer(size);
56+
}
57+
5458
function Parser() {
5559
this.tState = START;
5660
this.value = undefined;
5761

5862
this.string = undefined; // string data
59-
this.stringBuffer = Buffer.alloc ? Buffer.alloc(STRING_BUFFER_SIZE) : new Buffer(STRING_BUFFER_SIZE);
63+
this.stringBuffer = alloc(STRING_BUFFER_SIZE);
6064
this.stringBufferOffset = 0;
6165
this.unicode = undefined; // unicode escapes
6266
this.highSurrogate = undefined;
@@ -67,7 +71,7 @@ function Parser() {
6771
this.state = VALUE;
6872
this.bytes_remaining = 0; // number of bytes remaining in multi byte utf8 char to read after split boundary
6973
this.bytes_in_sequence = 0; // bytes in multi byte utf8 char to read
70-
this.temp_buffs = { "2": new Buffer(2), "3": new Buffer(3), "4": new Buffer(4) }; // for rebuilding chars split before boundary is reached
74+
this.temp_buffs = { "2": alloc(2), "3": alloc(3), "4": alloc(4) }; // for rebuilding chars split before boundary is reached
7175

7276
// Stream offset
7377
this.offset = -1;

0 commit comments

Comments
 (0)