Skip to content

Commit c7e4835

Browse files
committed
chore: kill ListWrapper.create() and .push().
These wrappers are not natively understood by ts2dart. Removing them will improve Dart2JS compilation due to fewer megamorphic calls to List functions. It also makes Angular code more succinct and improves type safety in Angular due to better type inference of the Array component type. This change exposed several bugs in Angular.
1 parent 6af41a4 commit c7e4835

File tree

88 files changed

+360
-387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+360
-387
lines changed

modules/angular2/src/change_detection/abstract_change_detector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ export class AbstractChangeDetector extends ChangeDetector {
1717
}
1818

1919
addChild(cd: ChangeDetector): void {
20-
ListWrapper.push(this.lightDomChildren, cd);
20+
this.lightDomChildren.push(cd);
2121
cd.parent = this;
2222
}
2323

2424
removeChild(cd: ChangeDetector): void { ListWrapper.remove(this.lightDomChildren, cd); }
2525

2626
addShadowDomChild(cd: ChangeDetector): void {
27-
ListWrapper.push(this.shadowDomChildren, cd);
27+
this.shadowDomChildren.push(cd);
2828
cd.parent = this;
2929
}
3030

modules/angular2/src/change_detection/coalesce.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {RecordType, ProtoRecord} from './proto_record';
1313
* replaced with very cheap SELF records.
1414
*/
1515
export function coalesce(records: List<ProtoRecord>): List<ProtoRecord> {
16-
var res: List<ProtoRecord> = ListWrapper.create();
16+
var res: List<ProtoRecord> = [];
1717
var indexMap: Map<number, number> = MapWrapper.create();
1818

1919
for (var i = 0; i < records.length; ++i) {
@@ -22,14 +22,14 @@ export function coalesce(records: List<ProtoRecord>): List<ProtoRecord> {
2222
var matchingRecord = _findMatching(record, res);
2323

2424
if (isPresent(matchingRecord) && record.lastInBinding) {
25-
ListWrapper.push(res, _selfRecord(record, matchingRecord.selfIndex, res.length + 1));
25+
res.push(_selfRecord(record, matchingRecord.selfIndex, res.length + 1));
2626
MapWrapper.set(indexMap, r.selfIndex, matchingRecord.selfIndex);
2727

2828
} else if (isPresent(matchingRecord) && !record.lastInBinding) {
2929
MapWrapper.set(indexMap, r.selfIndex, matchingRecord.selfIndex);
3030

3131
} else {
32-
ListWrapper.push(res, record);
32+
res.push(record);
3333
MapWrapper.set(indexMap, r.selfIndex, record.selfIndex);
3434
}
3535
}

modules/angular2/src/change_detection/parser/lexer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ enum TokenType {
2323
var tokens = [];
2424
var token = scanner.scanToken();
2525
while (token != null) {
26-
ListWrapper.push(tokens, token);
26+
tokens.push(token);
2727
token = scanner.scanToken();
2828
}
2929
return tokens;

modules/angular2/src/change_detection/parser/parser.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ export class Parser {
9999
var part = parts[i];
100100
if (i % 2 === 0) {
101101
// fixed string
102-
ListWrapper.push(strings, part);
102+
strings.push(part);
103103
} else {
104104
var tokens = this._lexer.tokenize(part);
105105
var ast = new _ParseAST(input, location, tokens, this._reflector, false).parseChain();
106-
ListWrapper.push(expressions, ast);
106+
expressions.push(ast);
107107
}
108108
}
109109
return new ASTWithSource(new Interpolation(strings, expressions), input, location);
@@ -194,7 +194,7 @@ class _ParseAST {
194194
var exprs = [];
195195
while (this.index < this.tokens.length) {
196196
var expr = this.parsePipe();
197-
ListWrapper.push(exprs, expr);
197+
exprs.push(expr);
198198

199199
if (this.optionalCharacter($SEMICOLON)) {
200200
if (!this.parseAction) {
@@ -222,7 +222,7 @@ class _ParseAST {
222222
var name = this.expectIdentifierOrKeyword();
223223
var args = [];
224224
while (this.optionalCharacter($COLON)) {
225-
ListWrapper.push(args, this.parsePipe());
225+
args.push(this.parsePipe());
226226
}
227227
result = new Pipe(result, name, args, true);
228228
} while (this.optionalOperator("|"));
@@ -456,7 +456,7 @@ class _ParseAST {
456456
var result = [];
457457
if (!this.next.isCharacter(terminator)) {
458458
do {
459-
ListWrapper.push(result, this.parsePipe());
459+
result.push(this.parsePipe());
460460
} while (this.optionalCharacter($COMMA));
461461
}
462462
return result;
@@ -469,9 +469,9 @@ class _ParseAST {
469469
if (!this.optionalCharacter($RBRACE)) {
470470
do {
471471
var key = this.expectIdentifierOrKeywordOrString();
472-
ListWrapper.push(keys, key);
472+
keys.push(key);
473473
this.expectCharacter($COLON);
474-
ListWrapper.push(values, this.parsePipe());
474+
values.push(this.parsePipe());
475475
} while (this.optionalCharacter($COMMA));
476476
this.expectCharacter($RBRACE);
477477
}
@@ -500,7 +500,7 @@ class _ParseAST {
500500
if (this.next.isCharacter($RPAREN)) return [];
501501
var positionals = [];
502502
do {
503-
ListWrapper.push(positionals, this.parsePipe());
503+
positionals.push(this.parsePipe());
504504
} while (this.optionalCharacter($COMMA));
505505
return positionals;
506506
}
@@ -522,7 +522,7 @@ class _ParseAST {
522522
var exprs = [];
523523
while (this.index < this.tokens.length && !this.next.isCharacter($RBRACE)) {
524524
var expr = this.parseExpression();
525-
ListWrapper.push(exprs, expr);
525+
exprs.push(expr);
526526

527527
if (this.optionalCharacter($SEMICOLON)) {
528528
while (this.optionalCharacter($SEMICOLON)) {
@@ -581,7 +581,7 @@ class _ParseAST {
581581
var source = this.input.substring(start, this.inputIndex);
582582
expression = new ASTWithSource(ast, source, this.location);
583583
}
584-
ListWrapper.push(bindings, new TemplateBinding(key, keyIsVar, name, expression));
584+
bindings.push(new TemplateBinding(key, keyIsVar, name, expression));
585585
if (!this.optionalCharacter($SEMICOLON)) {
586586
this.optionalCharacter($COMMA);
587587
}

modules/angular2/src/change_detection/pipes/iterable_changes.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,26 +448,26 @@ export class IterableChanges extends Pipe {
448448

449449
var list = [];
450450
for (record = this._itHead; record !== null; record = record._next) {
451-
ListWrapper.push(list, record);
451+
list.push(record);
452452
}
453453

454454
var previous = [];
455455
for (record = this._previousItHead; record !== null; record = record._nextPrevious) {
456-
ListWrapper.push(previous, record);
456+
previous.push(record);
457457
}
458458

459459
var additions = [];
460460
for (record = this._additionsHead; record !== null; record = record._nextAdded) {
461-
ListWrapper.push(additions, record);
461+
additions.push(record);
462462
}
463463
var moves = [];
464464
for (record = this._movesHead; record !== null; record = record._nextMoved) {
465-
ListWrapper.push(moves, record);
465+
moves.push(record);
466466
}
467467

468468
var removals = [];
469469
for (record = this._removalsHead; record !== null; record = record._nextRemoved) {
470-
ListWrapper.push(removals, record);
470+
removals.push(record);
471471
}
472472

473473
return "collection: " + list.join(', ') + "\n" + "previous: " + previous.join(', ') + "\n" +

modules/angular2/src/change_detection/pipes/keyvalue_changes.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,19 +299,19 @@ export class KeyValueChanges extends Pipe {
299299
var record: KVChangeRecord;
300300

301301
for (record = this._mapHead; record !== null; record = record._next) {
302-
ListWrapper.push(items, stringify(record));
302+
items.push(stringify(record));
303303
}
304304
for (record = this._previousMapHead; record !== null; record = record._nextPrevious) {
305-
ListWrapper.push(previous, stringify(record));
305+
previous.push(stringify(record));
306306
}
307307
for (record = this._changesHead; record !== null; record = record._nextChanged) {
308-
ListWrapper.push(changes, stringify(record));
308+
changes.push(stringify(record));
309309
}
310310
for (record = this._additionsHead; record !== null; record = record._nextAdded) {
311-
ListWrapper.push(additions, stringify(record));
311+
additions.push(stringify(record));
312312
}
313313
for (record = this._removalsHead; record !== null; record = record._nextRemoved) {
314-
ListWrapper.push(removals, stringify(record));
314+
removals.push(stringify(record));
315315
}
316316

317317
return "map: " + items.join(', ') + "\n" + "previous: " + previous.join(', ') + "\n" +

modules/angular2/src/change_detection/proto_change_detector.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ export class ProtoRecordBuilder {
8282

8383
_appendRecords(b: BindingRecord, variableNames: List<string>) {
8484
if (b.isDirectiveLifecycle()) {
85-
ListWrapper.push(
86-
this.records,
87-
new ProtoRecord(RecordType.DIRECTIVE_LIFECYCLE, b.lifecycleEvent, null, [], [], -1, null,
88-
this.records.length + 1, b, null, false, false));
85+
this.records.push(new ProtoRecord(RecordType.DIRECTIVE_LIFECYCLE, b.lifecycleEvent, null, [],
86+
[], -1, null, this.records.length + 1, b, null, false,
87+
false));
8988
} else {
9089
_ConvertAstIntoProtoRecords.append(this.records, b, variableNames);
9190
}
@@ -215,13 +214,13 @@ class _ConvertAstIntoProtoRecords implements AstVisitor {
215214
_addRecord(type, name, funcOrValue, args, fixedArgs, context) {
216215
var selfIndex = this._records.length + 1;
217216
if (context instanceof DirectiveIndex) {
218-
ListWrapper.push(this._records, new ProtoRecord(type, name, funcOrValue, args, fixedArgs, -1,
219-
context, selfIndex, this._bindingRecord,
220-
this._expressionAsString, false, false));
217+
this._records.push(new ProtoRecord(type, name, funcOrValue, args, fixedArgs, -1, context,
218+
selfIndex, this._bindingRecord, this._expressionAsString,
219+
false, false));
221220
} else {
222-
ListWrapper.push(this._records, new ProtoRecord(type, name, funcOrValue, args, fixedArgs,
223-
context, null, selfIndex, this._bindingRecord,
224-
this._expressionAsString, false, false));
221+
this._records.push(new ProtoRecord(type, name, funcOrValue, args, fixedArgs, context, null,
222+
selfIndex, this._bindingRecord, this._expressionAsString,
223+
false, false));
225224
}
226225
return selfIndex;
227226
}

modules/angular2/src/core/application.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,9 @@ export class ApplicationRef {
342342
function _createAppInjector(appComponentType: Type, bindings: List<Type | Binding | List<any>>,
343343
zone: NgZone): Injector {
344344
if (isBlank(_rootInjector)) _rootInjector = Injector.resolveAndCreate(_rootBindings);
345-
var mergedBindings = isPresent(bindings) ?
346-
ListWrapper.concat(_injectorBindings(appComponentType), bindings) :
347-
_injectorBindings(appComponentType);
348-
ListWrapper.push(mergedBindings, bind(NgZone).toValue(zone));
345+
var mergedBindings: any[] =
346+
isPresent(bindings) ? ListWrapper.concat(_injectorBindings(appComponentType), bindings) :
347+
_injectorBindings(appComponentType);
348+
mergedBindings.push(bind(NgZone).toValue(zone));
349349
return _rootInjector.resolveAndCreateChild(mergedBindings);
350350
}

modules/angular2/src/core/compiler/base_query_list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class BaseQueryList<T> {
2222
}
2323

2424
add(obj) {
25-
ListWrapper.push(this._results, obj);
25+
this._results.push(obj);
2626
this._dirty = true;
2727
}
2828

@@ -33,7 +33,7 @@ export class BaseQueryList<T> {
3333
}
3434
}
3535

36-
onChange(callback) { ListWrapper.push(this._callbacks, callback); }
36+
onChange(callback) { this._callbacks.push(callback); }
3737

3838
removeCallback(callback) { ListWrapper.remove(this._callbacks, callback); }
3939

modules/angular2/src/core/compiler/compiler.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ export class Compiler {
187187
(nestedPv: AppProtoView) => { elementBinder.nestedProtoView = nestedPv; };
188188
var nestedCall = this._compile(nestedComponent);
189189
if (isPromise(nestedCall)) {
190-
ListWrapper.push(nestedPVPromises,
191-
(<Promise<AppProtoView>>nestedCall).then(elementBinderDone));
190+
nestedPVPromises.push((<Promise<AppProtoView>>nestedCall).then(elementBinderDone));
192191
} else {
193192
elementBinderDone(<AppProtoView>nestedCall);
194193
}
@@ -206,7 +205,7 @@ export class Compiler {
206205
ListWrapper.forEach(protoViews, (protoView) => {
207206
ListWrapper.forEach(protoView.elementBinders, (elementBinder) => {
208207
if (isPresent(elementBinder.componentDirective)) {
209-
ListWrapper.push(componentElementBinders, elementBinder);
208+
componentElementBinders.push(elementBinder);
210209
}
211210
});
212211
});
@@ -254,7 +253,7 @@ export class Compiler {
254253
if (isArray(item)) {
255254
this._flattenList(item, out);
256255
} else {
257-
ListWrapper.push(out, item);
256+
out.push(item);
258257
}
259258
}
260259
}

0 commit comments

Comments
 (0)