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

Side by Side Diff: runtime/lib/integers.dart

Issue 22640019: Fix for running with --throw_on_javascript_int_overflow: recognize pattern (a << b) & mask and test… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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
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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 165
166 int pow(int exponent) { 166 int pow(int exponent) {
167 // Exponentiation by squaring. 167 // Exponentiation by squaring.
168 int base = this; 168 int base = this;
169 int result = 1; 169 int result = 1;
170 while (exponent != 0) { 170 while (exponent != 0) {
171 if ((exponent & 1) == 1) { 171 if ((exponent & 1) == 1) {
172 result *= base; 172 result *= base;
173 } 173 }
174 exponent >>= 1; 174 exponent >>= 1;
175 base *= base; 175 // Skip unnecessary operation (can overflow to Mint or Bigint).
176 if (exponent != 0) {
177 base *= base;
178 }
176 } 179 }
177 return result; 180 return result;
178 } 181 }
179 182
180 String toStringAsFixed(int fractionDigits) { 183 String toStringAsFixed(int fractionDigits) {
181 return this.toDouble().toStringAsFixed(fractionDigits); 184 return this.toDouble().toStringAsFixed(fractionDigits);
182 } 185 }
183 String toStringAsExponential([int fractionDigits]) { 186 String toStringAsExponential([int fractionDigits]) {
184 return this.toDouble().toStringAsExponential(fractionDigits); 187 return this.toDouble().toStringAsExponential(fractionDigits);
185 } 188 }
(...skipping 20 matching lines...) Expand all
206 if (temp.isEmpty) { 209 if (temp.isEmpty) {
207 return "0"; 210 return "0";
208 } 211 }
209 StringBuffer buffer = new StringBuffer(); 212 StringBuffer buffer = new StringBuffer();
210 if (isNegative) buffer.write("-"); 213 if (isNegative) buffer.write("-");
211 for (int i = temp.length - 1; i >= 0; i--) { 214 for (int i = temp.length - 1; i >= 0; i--) {
212 buffer.write(table[temp[i]]); 215 buffer.write(table[temp[i]]);
213 } 216 }
214 return buffer.toString(); 217 return buffer.toString();
215 } 218 }
219
220 _leftShiftWithMask32(count, mask) native "Integer_leftShiftWithMask32";
216 } 221 }
217 222
218 class _Smi extends _IntegerImplementation implements int { 223 class _Smi extends _IntegerImplementation implements int {
219 factory _Smi._uninstantiable() { 224 factory _Smi._uninstantiable() {
220 throw new UnsupportedError( 225 throw new UnsupportedError(
221 "_Smi can only be allocated by the VM"); 226 "_Smi can only be allocated by the VM");
222 } 227 }
223 int get hashCode { 228 int get hashCode {
224 return this; 229 return this;
225 } 230 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } else { 300 } else {
296 return 0; 301 return 0;
297 } 302 }
298 } 303 }
299 int _shlFromInt(int other) native "Bigint_shlFromInt"; 304 int _shlFromInt(int other) native "Bigint_shlFromInt";
300 305
301 int pow(int exponent) { 306 int pow(int exponent) {
302 throw "Bigint.pow not implemented"; 307 throw "Bigint.pow not implemented";
303 } 308 }
304 } 309 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698