Chromium Code Reviews| Index: pkg/compiler/lib/src/js_backend/constant_emitter.dart |
| diff --git a/pkg/compiler/lib/src/js_backend/constant_emitter.dart b/pkg/compiler/lib/src/js_backend/constant_emitter.dart |
| index 2773144dbc285b195e1ca13073a83b28f6c2610b..d4e57fb4717df427d4bd7143626ba143052935b1 100644 |
| --- a/pkg/compiler/lib/src/js_backend/constant_emitter.dart |
| +++ b/pkg/compiler/lib/src/js_backend/constant_emitter.dart |
| @@ -202,7 +202,22 @@ class ConstantLiteralEmitter |
| @override |
| jsAst.Expression visitInt(IntConstantValue constant, [_]) { |
| - return new jsAst.LiteralNumber('${constant.primitiveValue}'); |
| + int primitiveValue = constant.primitiveValue; |
| + // Since we are in JavaScript we can shorten long integers to their |
| + // shorter exponential representation. |
| + // For example: "1e+4" is shorter than "10000". |
|
sra1
2015/02/20 17:02:54
The + is not necessary, making "1e3" shorter than
floitsch
2015/02/20 20:23:20
https://codereview.chromium.org/938323003
|
| + // |
| + // Note that this shortening apparently loses precision for big numbers |
| + // (like 1234567890123456789012345 which becomes 1.2345678901234568e+24). |
| + // However, since JavaScript engines implicitly convert to double, these |
|
sra1
2015/02/20 17:02:54
nit. They don't 'implicitly convert to' so much as
floitsch
2015/02/20 20:23:20
done in https://codereview.chromium.org/938323003
|
| + // digits are lost anyway. |
| + if (primitiveValue.abs() >= 10000) { |
| + String exponential = primitiveValue.toStringAsExponential(); |
| + String decimal = primitiveValue.toString(); |
| + return new jsAst.LiteralNumber( |
| + (exponential.length < decimal.length) ? exponential : decimal); |
| + } |
| + return new jsAst.LiteralNumber('$primitiveValue'); |
| } |
| @override |