Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(729)

Unified Diff: runtime/vm/object.cc

Issue 9113043: Implement Double.{toString, toStringAsExponential, toStringAsPrecision} (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated status files. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/double_conversion.cc ('k') | tests/co19/co19-leg.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 305ba943dc2df6a886d079a712e667c7352a11eb..2ec884f6bae2dfda35398560ae6799833b1ffb47 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"
@@ -6265,22 +6266,12 @@ 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;
- 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;
- }
- }
- return chars;
+ const int kBufferSize = 128;
+ char* buffer = reinterpret_cast<char*>(
+ Isolate::Current()->current_zone()->Allocate(kBufferSize));
+ buffer[kBufferSize - 1] = '\0';
+ DoubleToCString(value(), buffer, kBufferSize);
+ return buffer;
}
« no previous file with comments | « runtime/vm/double_conversion.cc ('k') | tests/co19/co19-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698