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

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: Address comment 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
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index ecd63e0205d53c58125abc328347963d8999ccc7..176503f3f6d3d9ee0740693c7ae300794ca768fb 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -17,6 +17,7 @@
#include "vm/dart.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"
@@ -5967,21 +5968,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];
+ 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;
}

Powered by Google App Engine
This is Rietveld 408576698