Index: runtime/vm/object.cc |
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
index 9662afe3d7c30277410764a8cc1f9a68b2b7be96..55b48501adb8ce9fab6b7885642c5dc42b76ae0a 100644 |
--- a/runtime/vm/object.cc |
+++ b/runtime/vm/object.cc |
@@ -18,6 +18,7 @@ |
#include "vm/dart_api_state.h" |
#include "vm/dart_entry.h" |
#include "vm/debuginfo.h" |
+#include "vm/double_conversion.h" |
#include "vm/exceptions.h" |
#include "vm/growable_array.h" |
#include "vm/heap.h" |
@@ -6085,21 +6086,15 @@ const char* Double::ToCString() const { |
if (isinf(value())) { |
return value() < 0 ? "-Infinity" : "Infinity"; |
} |
- const char* kFormat = "%f"; |
- // Calculate the size of the string. |
- intptr_t len = OS::SNPrint(NULL, 0, kFormat, value()) + 1; |
+ const int kBufferSize = 128; |
+ char buffer[kBufferSize]; |
Ivan Posva
2012/02/27 14:47:14
Please avoid stack allocated buffers that are bein
floitsch
2012/02/27 19:55:40
Done.
|
+ int len; |
+ bool status = DoubleToCString(value(), buffer, kBufferSize, &len); |
+ ASSERT(status); |
+ |
char* chars = reinterpret_cast<char*>( |
Isolate::Current()->current_zone()->Allocate(len)); |
- OS::SNPrint(chars, len, kFormat, value()); |
- // Eliminate trailing 0s, but leave one digit after '.'. |
- // 'chars' is null terminated. |
- for (intptr_t i = len - 2; i >= 1; i--) { |
- if ((chars[i] == '0') && (chars[i - 1] != '.')) { |
- chars[i] = '\0'; |
- } else { |
- break; |
- } |
- } |
+ memmove(chars, buffer, len); |
return chars; |
} |