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

Unified Diff: runtime/lib/integers.dart

Issue 14629015: Implement Smi.toString in Dart instead of calling to C++ natives. Large performance improvement. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/integers.dart
===================================================================
--- runtime/lib/integers.dart (revision 22330)
+++ runtime/lib/integers.dart (working copy)
@@ -221,6 +221,32 @@
int operator ~() native "Smi_bitNegate";
int _shrFromInt(int other) native "Smi_shrFromInt";
int _shlFromInt(int other) native "Smi_shlFromInt";
+
+ String toString() {
+ if (this == 0) return "0";
+ var reversed = new List();
+ var val = this < 0 ? -this : this;
+ while (val > 0) {
+ reversed.add((val % 10) + 0x30);
+ val = val ~/ 10;
+ }
+ final int numDigits = reversed.length;
+ List digits;
+ int i;
+ if (this < 0) {
+ digits = new List(numDigits + 1);
+ digits[0] = 0x2D; // '-'.
+ i = 1;
+ } else {
+ digits = new List(numDigits);
+ i = 0;
+ }
+ int ri = reversed.length - 1;
+ for (; i < digits.length; i++, ri--) {
+ digits[i] = reversed[ri];
+ }
+ return _StringBase.createFromCharCodes(digits);
+ }
}
// Represents integers that cannot be represented by Smi but fit into 64bits.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698