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

Side by Side Diff: pkg/compiler/lib/src/constants/values.dart

Issue 1492233002: Constant folding of indexers (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years 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
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 library dart2js.constants.values; 5 library dart2js.constants.values;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../core_types.dart'; 8 import '../core_types.dart';
9 import '../dart_types.dart'; 9 import '../dart_types.dart';
10 import '../elements/elements.dart' 10 import '../elements/elements.dart'
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 } 495 }
496 sb.write('])'); 496 sb.write('])');
497 return sb.toString(); 497 return sb.toString();
498 } 498 }
499 } 499 }
500 500
501 class MapConstantValue extends ObjectConstantValue { 501 class MapConstantValue extends ObjectConstantValue {
502 final List<ConstantValue> keys; 502 final List<ConstantValue> keys;
503 final List<ConstantValue> values; 503 final List<ConstantValue> values;
504 final int hashCode; 504 final int hashCode;
505 Map<ConstantValue, ConstantValue> _lookupMap;
505 506
506 MapConstantValue(InterfaceType type, 507 MapConstantValue(InterfaceType type,
507 List<ConstantValue> keys, 508 List<ConstantValue> keys,
508 List<ConstantValue> values) 509 List<ConstantValue> values)
509 : this.keys = keys, 510 : this.keys = keys,
510 this.values = values, 511 this.values = values,
511 this.hashCode = Hashing.listHash(values, 512 this.hashCode = Hashing.listHash(values,
512 Hashing.listHash(keys, 513 Hashing.listHash(keys,
513 Hashing.objectHash(type))), 514 Hashing.objectHash(type))),
514 super(type) { 515 super(type) {
(...skipping 17 matching lines...) Expand all
532 533
533 List<ConstantValue> getDependencies() { 534 List<ConstantValue> getDependencies() {
534 List<ConstantValue> result = <ConstantValue>[]; 535 List<ConstantValue> result = <ConstantValue>[];
535 result.addAll(keys); 536 result.addAll(keys);
536 result.addAll(values); 537 result.addAll(values);
537 return result; 538 return result;
538 } 539 }
539 540
540 int get length => keys.length; 541 int get length => keys.length;
541 542
543 ConstantValue lookup(ConstantValue key) {
544 var lookupMap = _lookupMap ??=
545 new Map<ConstantValue, ConstantValue>.fromIterables(keys, values);
546 return lookupMap[key];
547 }
548
542 accept(ConstantValueVisitor visitor, arg) => visitor.visitMap(this, arg); 549 accept(ConstantValueVisitor visitor, arg) => visitor.visitMap(this, arg);
543 550
544 String unparse() { 551 String unparse() {
545 StringBuffer sb = new StringBuffer(); 552 StringBuffer sb = new StringBuffer();
546 _unparseTypeArguments(sb); 553 _unparseTypeArguments(sb);
547 sb.write('{'); 554 sb.write('{');
548 for (int i = 0 ; i < length ; i++) { 555 for (int i = 0 ; i < length ; i++) {
549 if (i > 0) sb.write(','); 556 if (i > 0) sb.write(',');
550 sb.write(keys[i].unparse()); 557 sb.write(keys[i].unparse());
551 sb.write(':'); 558 sb.write(':');
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 752
746 @override 753 @override
747 DartType getType(CoreTypes types) => const DynamicType(); 754 DartType getType(CoreTypes types) => const DynamicType();
748 755
749 @override 756 @override
750 String toStructuredString() => 'NonConstant'; 757 String toStructuredString() => 'NonConstant';
751 758
752 @override 759 @override
753 String unparse() => '>>non-constant<<'; 760 String unparse() => '>>non-constant<<';
754 } 761 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/common/names.dart ('k') | pkg/compiler/lib/src/cps_ir/type_mask_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698