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

Side by Side Diff: lib/src/compiler/code_generator.dart

Issue 2006443002: Use factory constructor for list literals (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: Created 4 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
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | tool/input_sdk/private/js_array.dart » ('j') | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 import 'dart:collection' show HashMap, HashSet; 5 import 'dart:collection' show HashMap, HashSet;
6 import 'dart:math' show min, max; 6 import 'dart:math' show min, max;
7 7
8 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 8 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; 10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType;
(...skipping 4217 matching lines...) Expand 10 before | Expand all | Expand 10 after
4228 JS.Expression list = new JS.ArrayInitializer( 4228 JS.Expression list = new JS.ArrayInitializer(
4229 _visitList(node.elements) as List<JS.Expression>); 4229 _visitList(node.elements) as List<JS.Expression>);
4230 ParameterizedType type = node.staticType; 4230 ParameterizedType type = node.staticType;
4231 var elementType = type.typeArguments.single; 4231 var elementType = type.typeArguments.single;
4232 // TODO(jmesserly): analyzer will usually infer `List<Object>` because 4232 // TODO(jmesserly): analyzer will usually infer `List<Object>` because
4233 // that is the least upper bound of the element types. So we rarely 4233 // that is the least upper bound of the element types. So we rarely
4234 // generate a plain `List<dynamic>` anymore. 4234 // generate a plain `List<dynamic>` anymore.
4235 if (!elementType.isDynamic || isConst) { 4235 if (!elementType.isDynamic || isConst) {
4236 // dart.list helper internally depends on _interceptors.JSArray. 4236 // dart.list helper internally depends on _interceptors.JSArray.
4237 _declareBeforeUse(_jsArray); 4237 _declareBeforeUse(_jsArray);
4238 var typeRep = _emitType(elementType); 4238 if (isConst) {
4239 var helper = (isConst) ? 'constList' : 'list'; 4239 var typeRep = _emitType(elementType);
4240 list = js.call('dart.${helper}(#, #)', [list, typeRep]); 4240 list = js.call('dart.constList(#, #)', [list, typeRep]);
4241 } else {
4242 // Call `new JSArray<E>.of(list)`
4243 var jsArrayType = _jsArray.type.instantiate(type.typeArguments);
4244 list = js.call('#.of(#)', [_emitType(jsArrayType), list]);
4245 }
4241 } 4246 }
4242 return list; 4247 return list;
4243 } 4248 }
4244 if (isConst) return _cacheConst(emitList); 4249 if (isConst) return _cacheConst(emitList);
4245 return emitList(); 4250 return emitList();
4246 } 4251 }
4247 4252
4248 @override 4253 @override
4249 visitMapLiteral(MapLiteral node) { 4254 visitMapLiteral(MapLiteral node) {
4250 // TODO(jmesserly): we can likely make these faster. 4255 // TODO(jmesserly): we can likely make these faster.
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
4627 } 4632 }
4628 4633
4629 bool isLibraryPrefix(Expression node) => 4634 bool isLibraryPrefix(Expression node) =>
4630 node is SimpleIdentifier && node.staticElement is PrefixElement; 4635 node is SimpleIdentifier && node.staticElement is PrefixElement;
4631 4636
4632 LibraryElement _getLibrary(AnalysisContext c, String uri) => 4637 LibraryElement _getLibrary(AnalysisContext c, String uri) =>
4633 c.computeLibraryElement(c.sourceFactory.forUri(uri)); 4638 c.computeLibraryElement(c.sourceFactory.forUri(uri));
4634 4639
4635 bool _isDartRuntime(LibraryElement l) => 4640 bool _isDartRuntime(LibraryElement l) =>
4636 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; 4641 l.isInSdk && l.source.uri.toString() == 'dart:_runtime';
OLDNEW
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | tool/input_sdk/private/js_array.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698