Index: src/conversions.cc |
=================================================================== |
--- src/conversions.cc (revision 4092) |
+++ src/conversions.cc (working copy) |
@@ -31,6 +31,7 @@ |
#include "conversions-inl.h" |
#include "factory.h" |
+#include "grisu3.h" |
#include "scanner.h" |
namespace v8 { |
@@ -382,8 +383,17 @@ |
int decimal_point; |
int sign; |
- char* decimal_rep = dtoa(v, 0, 0, &decimal_point, &sign, NULL); |
- int length = StrLength(decimal_rep); |
+ char* decimal_rep; |
+ bool used_dtoa = false; |
+ char grisu_buffer[kGrisu3MaximalLength + 1]; |
+ int length; |
+ if (grisu3(v, grisu_buffer, &sign, &length, &decimal_point)) { |
+ decimal_rep = grisu_buffer; |
+ } else { |
+ decimal_rep = dtoa(v, 0, 0, &decimal_point, &sign, NULL); |
+ used_dtoa = true; |
+ length = StrLength(decimal_rep); |
+ } |
if (sign) builder.AddCharacter('-'); |
@@ -418,7 +428,7 @@ |
builder.AddFormatted("%d", exponent); |
} |
- freedtoa(decimal_rep); |
+ if (used_dtoa) freedtoa(decimal_rep); |
} |
} |
return builder.Finalize(); |