@@ -70,6 +70,8 @@ var INF_POSITIVE_BUFFER = [
70
70
71
71
var EXPONENT_REGEX = / ^ ( [ - + ] ) ? ( \d + ) ? $ / ;
72
72
73
+ var utils = require ( './parser/utils' ) ;
74
+
73
75
// Detect if the value is a digit
74
76
var isDigit = function ( value ) {
75
77
return ! isNaN ( parseInt ( value , 10 ) ) ;
@@ -143,7 +145,7 @@ var lessThan = function(left, right) {
143
145
} ;
144
146
145
147
// var longtoHex = function(value) {
146
- // var buffer = new Buffer (8);
148
+ // var buffer = utils.allocBuffer (8);
147
149
// var index = 0;
148
150
// // Encode the low 64 bits of the decimal
149
151
// // Encode low bits
@@ -160,7 +162,7 @@ var lessThan = function(left, right) {
160
162
// };
161
163
162
164
// var int32toHex = function(value) {
163
- // var buffer = new Buffer (4);
165
+ // var buffer = utils.allocBuffer (4);
164
166
// var index = 0;
165
167
// // Encode the low 64 bits of the decimal
166
168
// // Encode low bits
@@ -265,17 +267,17 @@ Decimal128.fromString = function(string) {
265
267
// Check if user passed Infinity or NaN
266
268
if ( ! isDigit ( string [ index ] ) && string [ index ] !== '.' ) {
267
269
if ( string [ index ] === 'i' || string [ index ] === 'I' ) {
268
- return new Decimal128 ( new Buffer ( isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER ) ) ;
270
+ return new Decimal128 ( utils . toBuffer ( isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER ) ) ;
269
271
} else if ( string [ index ] === 'N' ) {
270
- return new Decimal128 ( new Buffer ( NAN_BUFFER ) ) ;
272
+ return new Decimal128 ( utils . toBuffer ( NAN_BUFFER ) ) ;
271
273
}
272
274
}
273
275
274
276
// Read all the digits
275
277
while ( isDigit ( string [ index ] ) || string [ index ] === '.' ) {
276
278
if ( string [ index ] === '.' ) {
277
279
if ( sawRadix ) {
278
- return new Decimal128 ( new Buffer ( NAN_BUFFER ) ) ;
280
+ return new Decimal128 ( utils . toBuffer ( NAN_BUFFER ) ) ;
279
281
}
280
282
281
283
sawRadix = true ;
@@ -320,7 +322,7 @@ Decimal128.fromString = function(string) {
320
322
321
323
// No digits read
322
324
if ( ! match || ! match [ 2 ] ) {
323
- return new Decimal128 ( new Buffer ( NAN_BUFFER ) ) ;
325
+ return new Decimal128 ( utils . toBuffer ( NAN_BUFFER ) ) ;
324
326
}
325
327
326
328
// Get exponent
@@ -332,7 +334,7 @@ Decimal128.fromString = function(string) {
332
334
333
335
// Return not a number
334
336
if ( string [ index ] ) {
335
- return new Decimal128 ( new Buffer ( NAN_BUFFER ) ) ;
337
+ return new Decimal128 ( utils . toBuffer ( NAN_BUFFER ) ) ;
336
338
}
337
339
338
340
// Done reading input
@@ -380,7 +382,7 @@ Decimal128.fromString = function(string) {
380
382
exponent = EXPONENT_MAX ;
381
383
break ;
382
384
} else {
383
- return new Decimal128 ( new Buffer ( isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER ) ) ;
385
+ return new Decimal128 ( utils . toBuffer ( isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER ) ) ;
384
386
}
385
387
}
386
388
@@ -412,7 +414,7 @@ Decimal128.fromString = function(string) {
412
414
exponent = EXPONENT_MAX ;
413
415
break ;
414
416
} else {
415
- return new Decimal128 ( new Buffer ( isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER ) ) ;
417
+ return new Decimal128 ( utils . toBuffer ( isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER ) ) ;
416
418
}
417
419
}
418
420
}
@@ -462,7 +464,7 @@ Decimal128.fromString = function(string) {
462
464
digits [ dIdx ] = 1 ;
463
465
} else {
464
466
return new Decimal128 (
465
- new Buffer ( isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER )
467
+ utils . toBuffer ( isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER )
466
468
) ;
467
469
}
468
470
}
@@ -547,7 +549,7 @@ Decimal128.fromString = function(string) {
547
549
}
548
550
549
551
// Encode into a buffer
550
- var buffer = new Buffer ( 16 ) ;
552
+ var buffer = utils . allocBuffer ( 16 ) ;
551
553
index = 0 ;
552
554
553
555
// Encode the low 64 bits of the decimal
0 commit comments