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

Unified Diff: runtime/lib/integers.cc

Issue 24359002: Make smi.toString() do its work faster using native string helpers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 | « no previous file | runtime/lib/integers.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/integers.cc
diff --git a/runtime/lib/integers.cc b/runtime/lib/integers.cc
index 84dc9d6205fa1c82c40e82ebc78b3aff4ceb2af8..3bdd21c62b2fd529561623b25169e367f93c9dd1 100644
--- a/runtime/lib/integers.cc
+++ b/runtime/lib/integers.cc
@@ -344,6 +344,37 @@ DEFINE_NATIVE_ENTRY(Smi_bitLength, 1) {
return Smi::New(result);
}
+DEFINE_NATIVE_ENTRY(Smi_toString, 1) {
+ const Smi& operand = Smi::CheckedHandle(arguments->NativeArgAt(0));
+ if (FLAG_trace_intrinsified_natives) {
+ OS::Print("Smi_toString: %s\n", operand.ToCString());
+ }
+ // Maximal number of digits of a 63 bit number is 19. Add one for minus sign.
Lasse Reichstein Nielsen 2013/09/23 11:25:18 I decided against using OS::SNPrint(characters, 0,
+ const size_t kMaxLength = 20;
+ uint8_t characters[kMaxLength];
+ uint8_t* end = characters + kMaxLength;
+ uint8_t* cursor = end;
+ bool negative = false;
+ int64_t signed_value = operand.AsInt64Value();
+ uint64_t value;
+ if (signed_value < 0) {
+ negative = true;
+ value = -signed_value;
+ } else {
+ value = signed_value;
+ }
+ do {
+ uint64_t digit = value % 10;
+ value = (value - digit) / 10;
+ *--cursor = '0' + digit;
+ } while (value);
+ if (negative) {
+ *--cursor = '-';
+ }
+ intptr_t length = static_cast<intptr_t>(end - cursor);
+ return OneByteString::New(cursor, length, Heap::kNew);
+}
+
// Mint natives.
« no previous file with comments | « no previous file | runtime/lib/integers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698