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

Side by Side 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, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // TODO(srdjan): fix limitations. 5 // TODO(srdjan): fix limitations.
6 // - shift amount must be a Smi. 6 // - shift amount must be a Smi.
7 class _IntegerImplementation { 7 class _IntegerImplementation {
8 factory _IntegerImplementation._uninstantiable() { 8 factory _IntegerImplementation._uninstantiable() {
9 throw new UnsupportedError( 9 throw new UnsupportedError(
10 "_IntegerImplementation can only be allocated by the VM"); 10 "_IntegerImplementation can only be allocated by the VM");
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 factory _Smi._uninstantiable() { 214 factory _Smi._uninstantiable() {
215 throw new UnsupportedError( 215 throw new UnsupportedError(
216 "_Smi can only be allocated by the VM"); 216 "_Smi can only be allocated by the VM");
217 } 217 }
218 int get hashCode { 218 int get hashCode {
219 return this; 219 return this;
220 } 220 }
221 int operator ~() native "Smi_bitNegate"; 221 int operator ~() native "Smi_bitNegate";
222 int _shrFromInt(int other) native "Smi_shrFromInt"; 222 int _shrFromInt(int other) native "Smi_shrFromInt";
223 int _shlFromInt(int other) native "Smi_shlFromInt"; 223 int _shlFromInt(int other) native "Smi_shlFromInt";
224
225 String toString() {
226 if (this == 0) return "0";
227 var reversed = new List();
228 var val = this < 0 ? -this : this;
229 while (val > 0) {
230 reversed.add((val % 10) + 0x30);
231 val = val ~/ 10;
232 }
233 final int numDigits = reversed.length;
234 List digits;
235 int i;
236 if (this < 0) {
237 digits = new List(numDigits + 1);
238 digits[0] = 0x2D; // '-'.
239 i = 1;
240 } else {
241 digits = new List(numDigits);
242 i = 0;
243 }
244 int ri = reversed.length - 1;
245 for (; i < digits.length; i++, ri--) {
246 digits[i] = reversed[ri];
247 }
248 return _StringBase.createFromCharCodes(digits);
249 }
224 } 250 }
225 251
226 // Represents integers that cannot be represented by Smi but fit into 64bits. 252 // Represents integers that cannot be represented by Smi but fit into 64bits.
227 class _Mint extends _IntegerImplementation implements int { 253 class _Mint extends _IntegerImplementation implements int {
228 factory _Mint._uninstantiable() { 254 factory _Mint._uninstantiable() {
229 throw new UnsupportedError( 255 throw new UnsupportedError(
230 "_Mint can only be allocated by the VM"); 256 "_Mint can only be allocated by the VM");
231 } 257 }
232 int get hashCode { 258 int get hashCode {
233 return this; 259 return this;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 294 }
269 } 295 }
270 int _shlFromInt(int other) { 296 int _shlFromInt(int other) {
271 throw const OutOfMemoryError(); 297 throw const OutOfMemoryError();
272 } 298 }
273 299
274 int pow(int exponent) { 300 int pow(int exponent) {
275 throw "Bigint.pow not implemented"; 301 throw "Bigint.pow not implemented";
276 } 302 }
277 } 303 }
OLDNEW
« 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