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.
This commit is contained in:
Martin Probst
2015-06-17 11:17:21 -07:00
parent 6af41a4543
commit c7e48350d3
88 changed files with 360 additions and 387 deletions
@@ -30,7 +30,7 @@ import {resolveInternalDomProtoView} from 'angular2/src/render/dom/view/proto_vi
export function runCompilerCommonTests() {
describe('DomCompiler', function() {
var mockStepFactory;
var mockStepFactory: MockStepFactory;
function createCompiler(processClosure, urlData = null) {
if (isBlank(urlData)) {
@@ -117,8 +117,8 @@ export function runCompilerCommonTests() {
var completer = PromiseWrapper.completer();
var compiler = createCompiler((parent, current, control) => {
ListWrapper.push(mockStepFactory.subTaskPromises,
completer.promise.then((_) => { subTasksCompleted = true; }));
mockStepFactory.subTaskPromises.push(
completer.promise.then((_) => { subTasksCompleted = true; }));
});
// It should always return a Promise because the subtask is async
@@ -177,7 +177,7 @@ class MockStepFactory extends CompileStepFactory {
createSteps(viewDef, subTaskPromises) {
this.viewDef = viewDef;
this.subTaskPromises = subTaskPromises;
ListWrapper.forEach(this.subTaskPromises, (p) => ListWrapper.push(subTaskPromises, p));
ListWrapper.forEach(this.subTaskPromises, (p) => this.subTaskPromises.push(p));
return this.steps;
}
}
@@ -213,15 +213,15 @@ class IgnoreCurrentElementStep implements CompileStep {
}
}
function logEntry(log, parent, current) {
function logEntry(log: string[], parent, current) {
var parentId = '';
if (isPresent(parent)) {
parentId = DOM.getAttribute(parent.element, 'id') + '<';
}
ListWrapper.push(log, parentId + DOM.getAttribute(current.element, 'id'));
log.push(parentId + DOM.getAttribute(current.element, 'id'));
}
function createLoggerStep(log) {
function createLoggerStep(log: string[]) {
return new MockStep((parent, current, control) => { logEntry(log, parent, current); });
}
@@ -6,16 +6,17 @@ import {List, ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
export function main() {
describe('SelectorMatcher', () => {
var matcher, matched, selectableCollector, s1, s2, s3, s4;
var matcher, selectableCollector, s1, s2, s3, s4;
var matched: any[];
function reset() { matched = ListWrapper.create(); }
function reset() { matched = []; }
beforeEach(() => {
reset();
s1 = s2 = s3 = s4 = null;
selectableCollector = (selector, context) => {
ListWrapper.push(matched, selector);
ListWrapper.push(matched, context);
matched.push(selector);
matched.push(context);
};
matcher = new SelectorMatcher();
});
@@ -35,7 +35,7 @@ class LoggingEventDispatcher implements EventDispatcher {
constructor(log: List<List<any>>) { this.log = log; }
dispatchEvent(elementIndex: number, eventName: string, locals: Map<string, any>) {
ListWrapper.push(this.log, [elementIndex, eventName, locals]);
this.log.push([elementIndex, eventName, locals]);
return true;
}
}
@@ -93,10 +93,10 @@ export class DomTestbed {
createRootViews(protoViews: List<ProtoViewDto>): List<TestView> {
var views = [];
var lastView = this.createRootView(protoViews[0]);
ListWrapper.push(views, lastView);
views.push(lastView);
for (var i = 1; i < protoViews.length; i++) {
lastView = this.createComponentView(lastView.viewRef, 0, protoViews[i]);
ListWrapper.push(views, lastView);
views.push(lastView);
}
return views;
}
@@ -31,7 +31,7 @@ class FakeProtoView extends SpyObject {
@proxy
@IMPLEMENTS(DomView)
class FakeView extends SpyObject {
boundElements;
boundElements: any[];
proto;
constructor(containers = null, transitiveContentTagCount: number = 1) {
@@ -53,7 +53,7 @@ class FakeView extends SpyObject {
}
var boundElement = new DomElement(null, element, contentTag);
boundElement.viewContainer = vc;
ListWrapper.push(this.boundElements, boundElement);
this.boundElements.push(boundElement);
});
}
}
@@ -16,7 +16,6 @@ import {
proxy
} from 'angular2/test_lib';
import {isBlank} from 'angular2/src/facade/lang';
import {ListWrapper} from 'angular2/src/facade/collection';
import {DomProtoView} from 'angular2/src/render/dom/view/proto_view';
import {ElementBinder} from 'angular2/src/render/dom/view/element_binder';
@@ -42,8 +41,7 @@ export function main() {
var root = el('<div><div></div></div>');
var boundElements = [];
for (var i = 0; i < boundElementCount; i++) {
ListWrapper.push(boundElements,
new DomElement(pv.elementBinders[i], el('<span></span'), null));
boundElements.push(new DomElement(pv.elementBinders[i], el('<span></span'), null));
}
return new DomView(pv, [DOM.childNodes(root)[0]], [], boundElements);
}