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

Unified Diff: runtime/lib/integers.dart

Issue 247083002: Avoid comparing smi to mint in smi.toString(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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
diff --git a/runtime/lib/integers.dart b/runtime/lib/integers.dart
index 5c9f7d8578ab5efdc13be114244f4a65180811ce..e450cda5daa75710930ead37485006d549564333 100644
--- a/runtime/lib/integers.dart
+++ b/runtime/lib/integers.dart
@@ -294,11 +294,10 @@ class _Smi extends _IntegerImplementation implements int {
0x39, 0x36, 0x39, 0x37, 0x39, 0x38, 0x39, 0x39
];
- // Powers of 10 above 1000000 are indistinguishable.
+ // Powers of 10 above 1000000 are indistinguishable by eye.
static const int _POW_10_7 = 10000000;
static const int _POW_10_8 = 100000000;
static const int _POW_10_9 = 1000000000;
- static const int _POW_10_10 = 10000000000;
// Find the number of decimal digits in a positive smi.
static int _positiveBase10Length(var smi) {
@@ -311,15 +310,12 @@ class _Smi extends _IntegerImplementation implements int {
if (smi < 1000000) return 6;
return 7;
}
- if (smi < _POW_10_10) {
- if (smi < _POW_10_8) return 8;
- if (smi < _POW_10_9) return 9;
- return 10;
- }
- smi = smi ~/ _POW_10_10;
- if (smi < 10) return 11;
- if (smi < 100) return 12;
- return 10 + _positiveBase10Length(smi);
+ if (smi < _POW_10_8) return 8;
+ if (smi < _POW_10_9) return 9;
+ smi = smi ~/ _POW_10_9;
+ if (smi < 10) return 10;
+ if (smi < 100) return 11;
Anders Johnsen 2014/04/22 09:21:48 Add comment why we check for 10 and 11 here.
+ return 9 + _positiveBase10Length(smi);
}
String toString() {
@@ -373,15 +369,12 @@ class _Smi extends _IntegerImplementation implements int {
if (negSmi > -1000000) return 6;
return 7;
}
- if (negSmi > -_POW_10_10) {
- if (negSmi > -_POW_10_8) return 8;
- if (negSmi > -_POW_10_9) return 9;
- return 10;
- }
- negSmi = negSmi ~/ _POW_10_10;
- if (negSmi > -10) return 11;
- if (negSmi > -100) return 12;
- return 10 + _negativeBase10Length(negSmi);
+ if (negSmi > -_POW_10_8) return 8;
+ if (negSmi > -_POW_10_9) return 9;
+ negSmi = negSmi ~/ _POW_10_9;
+ if (negSmi > -10) return 10;
+ if (negSmi > -100) return 11;
Anders Johnsen 2014/04/22 09:21:48 Ditto.
+ return 9 + _negativeBase10Length(negSmi);
}
// Convert a negative smi to a string.
« 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