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

View File

@ -10,14 +10,14 @@ import {CompileStep} from './compile_step';
export class CompileControl {
_currentStepIndex: number = 0;
_parent: CompileElement = null;
_results = null;
_additionalChildren = null;
_results: any[] = null;
_additionalChildren: any[] = null;
_ignoreCurrentElement: boolean;
constructor(public _steps: List<CompileStep>) {}
// only public so that it can be used by compile_pipeline
internalProcess(results, startStepIndex, parent: CompileElement, current: CompileElement) {
internalProcess(results: any[], startStepIndex, parent: CompileElement, current: CompileElement) {
this._results = results;
var previousStepIndex = this._currentStepIndex;
var previousParent = this._parent;
@ -33,7 +33,7 @@ export class CompileControl {
}
if (!this._ignoreCurrentElement) {
ListWrapper.push(results, current);
results.push(current);
}
this._currentStepIndex = previousStepIndex;
@ -51,9 +51,9 @@ export class CompileControl {
addChild(element: CompileElement) {
if (isBlank(this._additionalChildren)) {
this._additionalChildren = ListWrapper.create();
this._additionalChildren = [];
}
ListWrapper.push(this._additionalChildren, element);
this._additionalChildren.push(element);
}
/**

View File

@ -63,10 +63,10 @@ export class CompileElement {
classList(): List<string> {
if (isBlank(this._classList)) {
this._classList = ListWrapper.create();
this._classList = [];
var elClassList = DOM.classList(this.element);
for (var i = 0; i < elClassList.length; i++) {
ListWrapper.push(this._classList, elClassList[i]);
this._classList.push(elClassList[i]);
}
}
return this._classList;

View File

@ -20,7 +20,7 @@ export class CompilePipeline {
if (isBlank(protoViewType)) {
protoViewType = ViewType.COMPONENT;
}
var results = ListWrapper.create();
var results = [];
var rootCompileElement = new CompileElement(rootElement, compilationCtxtDescription);
rootCompileElement.inheritedProtoView = new ProtoViewBuilder(rootElement, protoViewType);
rootCompileElement.isViewRoot = true;

View File

@ -74,7 +74,7 @@ export class DirectiveParser implements CompileStep {
componentDirective = directive;
elementBinder.setComponentId(directive.id);
} else {
ListWrapper.push(foundDirectiveIndices, directiveIndex);
foundDirectiveIndices.push(directiveIndex);
}
});
ListWrapper.forEach(foundDirectiveIndices, (directiveIndex) => {

View File

@ -32,13 +32,13 @@ export class CssSelector {
notSelectors: List<CssSelector> = [];
static parse(selector: string): List<CssSelector> {
var results = ListWrapper.create();
var _addResult = (res, cssSel) => {
var results: CssSelector[] = [];
var _addResult = (res: CssSelector[], cssSel) => {
if (cssSel.notSelectors.length > 0 && isBlank(cssSel.element) &&
ListWrapper.isEmpty(cssSel.classNames) && ListWrapper.isEmpty(cssSel.attrs)) {
cssSel.element = "*";
}
ListWrapper.push(res, cssSel);
res.push(cssSel);
};
var cssSelector = new CssSelector();
var matcher = RegExpWrapper.matcher(_SELECTOR_REGEXP, selector);
@ -52,7 +52,7 @@ export class CssSelector {
}
inNot = true;
current = new CssSelector();
ListWrapper.push(cssSelector.notSelectors, current);
cssSelector.notSelectors.push(current);
}
if (isPresent(match[2])) {
current.setElement(match[2]);
@ -92,16 +92,16 @@ export class CssSelector {
}
addAttribute(name: string, value: string = _EMPTY_ATTR_VALUE) {
ListWrapper.push(this.attrs, name.toLowerCase());
this.attrs.push(name.toLowerCase());
if (isPresent(value)) {
value = value.toLowerCase();
} else {
value = _EMPTY_ATTR_VALUE;
}
ListWrapper.push(this.attrs, value);
this.attrs.push(value);
}
addClassName(name: string) { ListWrapper.push(this.classNames, name.toLowerCase()); }
addClassName(name: string) { this.classNames.push(name.toLowerCase()); }
toString(): string {
var res = '';
@ -141,11 +141,11 @@ export class SelectorMatcher {
return notMatcher;
}
private _elementMap: Map<string, List<string>> = MapWrapper.create();
private _elementMap: Map<string, List<SelectorContext>> = MapWrapper.create();
private _elementPartialMap: Map<string, SelectorMatcher> = MapWrapper.create();
private _classMap: Map<string, List<string>> = MapWrapper.create();
private _classMap: Map<string, List<SelectorContext>> = MapWrapper.create();
private _classPartialMap: Map<string, SelectorMatcher> = MapWrapper.create();
private _attrValueMap: Map<string, Map<string, List<string>>> = MapWrapper.create();
private _attrValueMap: Map<string, Map<string, List<SelectorContext>>> = MapWrapper.create();
private _attrValuePartialMap: Map<string, Map<string, SelectorMatcher>> = MapWrapper.create();
private _listContexts: List<SelectorListContext> = [];
@ -153,7 +153,7 @@ export class SelectorMatcher {
var listContext = null;
if (cssSelectors.length > 1) {
listContext = new SelectorListContext(cssSelectors);
ListWrapper.push(this._listContexts, listContext);
this._listContexts.push(listContext);
}
for (var i = 0; i < cssSelectors.length; i++) {
this._addSelectable(cssSelectors[i], callbackCtxt, listContext);
@ -220,13 +220,14 @@ export class SelectorMatcher {
}
}
private _addTerminal(map: Map<string, List<string>>, name: string, selectable: SelectorContext) {
private _addTerminal(map: Map<string, List<SelectorContext>>, name: string,
selectable: SelectorContext) {
var terminalList = MapWrapper.get(map, name);
if (isBlank(terminalList)) {
terminalList = ListWrapper.create();
terminalList = [];
MapWrapper.set(map, name, terminalList);
}
ListWrapper.push(terminalList, selectable);
terminalList.push(selectable);
}
private _addPartial(map: Map<string, SelectorMatcher>, name: string): SelectorMatcher {
@ -297,8 +298,8 @@ export class SelectorMatcher {
return result;
}
_matchTerminal(map: Map<string, List<string>>, name, cssSelector: CssSelector,
matchedCallback /*: (CssSelector, any) => void*/): boolean {
_matchTerminal(map: Map<string, List<SelectorContext>>, name, cssSelector: CssSelector,
matchedCallback: (CssSelector, any) => void): boolean {
if (isBlank(map) || isBlank(name)) {
return false;
}

View File

@ -151,7 +151,7 @@ export class DomRenderer extends Renderer {
}
// add global events
view.eventHandlerRemovers = ListWrapper.create();
view.eventHandlerRemovers = [];
var binders = view.proto.elementBinders;
for (var binderIdx = 0; binderIdx < binders.length; binderIdx++) {
var binder = binders[binderIdx];
@ -160,7 +160,7 @@ export class DomRenderer extends Renderer {
var globalEvent = binder.globalEvents[i];
var remover = this._createGlobalEventListener(view, binderIdx, globalEvent.name,
globalEvent.target, globalEvent.fullName);
ListWrapper.push(view.eventHandlerRemovers, remover);
view.eventHandlerRemovers.push(remover);
}
}
}

View File

@ -55,7 +55,7 @@ export class LightDom {
for (var i = 0; i < els.length; i++) {
var el = els[i];
if (isPresent(el.contentTag)) {
ListWrapper.push(acc, el.contentTag);
acc.push(el.contentTag);
}
if (isPresent(el.viewContainer)) {
ListWrapper.forEach(el.viewContainer.contentTagContainers(),
@ -83,10 +83,10 @@ export class LightDom {
} else if (isPresent(content)) {
res = ListWrapper.concat(res, content.nodes());
} else {
ListWrapper.push(res, root.node);
res.push(root.node);
}
} else {
ListWrapper.push(res, root.node);
res.push(root.node);
}
}
return res;

View File

@ -303,7 +303,7 @@ export class ShadowCss {
var p = parts[i];
if (isBlank(p)) break;
p = p.trim();
ListWrapper.push(r, partReplacer(_polyfillHostNoCombinator, p, m[3]));
r.push(partReplacer(_polyfillHostNoCombinator, p, m[3]));
}
return r.join(',');
} else {
@ -392,7 +392,7 @@ export class ShadowCss {
this._applyStrictSelectorScope(p, scopeSelector) :
this._applySelectorScope(p, scopeSelector, hostSelector);
}
ListWrapper.push(r, p);
r.push(p);
}
return r.join(', ');
}

View File

@ -31,7 +31,7 @@ export class ShadowDomCompileStep implements CompileStep {
var stylePromise = this._shadowDomStrategy.processStyleElement(
this._template.componentId, this._template.templateAbsUrl, current.element);
if (isPresent(stylePromise) && isPromise(stylePromise)) {
ListWrapper.push(this._subTaskPromises, stylePromise);
this._subTaskPromises.push(stylePromise);
}
// Style elements should not be further processed by the compiler, as they can not contain

View File

@ -73,7 +73,7 @@ export class StyleInliner {
// Importing again might cause a circular dependency
promise = PromiseWrapper.resolve(prefix);
} else {
ListWrapper.push(inlinedUrls, url);
inlinedUrls.push(url);
promise = PromiseWrapper.then(this._xhr.get(url), (rawCss) => {
// resolve nested @import rules
var inlinedCss = this._inlineImports(rawCss, url, inlinedUrls);
@ -88,7 +88,7 @@ export class StyleInliner {
}
}, (error) => `/* failed to import ${url} */\n`);
}
ListWrapper.push(promises, promise);
promises.push(promise);
partIndex += 2;
}

View File

@ -27,7 +27,7 @@ export class ProtoViewBuilder {
bindElement(element, description = null): ElementBinderBuilder {
var builder = new ElementBinderBuilder(this.elements.length, element, description);
ListWrapper.push(this.elements, builder);
this.elements.push(builder);
DOM.addClass(element, NG_BINDING_CLASS);
return builder;
@ -90,7 +90,7 @@ export class ProtoViewBuilder {
transitiveContentTagCount++;
}
var parentIndex = isPresent(ebb.parent) ? ebb.parent.index : -1;
ListWrapper.push(apiElementBinders, new api.ElementBinder({
apiElementBinders.push(new api.ElementBinder({
index: ebb.index,
parentIndex: parentIndex,
distanceToParent: ebb.distanceToParent,
@ -103,22 +103,21 @@ export class ProtoViewBuilder {
readAttributes: ebb.readAttributes
}));
var elementIsEmpty = this._isEmptyElement(ebb.element);
ListWrapper.push(renderElementBinders, new ElementBinder({
textNodeIndices: ebb.textBindingIndices,
contentTagSelector: ebb.contentTagSelector,
parentIndex: parentIndex,
distanceToParent: ebb.distanceToParent,
nestedProtoView: isPresent(nestedProtoView) ?
resolveInternalDomProtoView(nestedProtoView.render) :
null,
componentId: ebb.componentId,
eventLocals: new LiteralArray(ebb.eventBuilder.buildEventLocals()),
localEvents: ebb.eventBuilder.buildLocalEvents(),
globalEvents: ebb.eventBuilder.buildGlobalEvents(),
hostActions: hostActions,
propertySetters: propertySetters,
elementIsEmpty: elementIsEmpty
}));
renderElementBinders.push(new ElementBinder({
textNodeIndices: ebb.textBindingIndices,
contentTagSelector: ebb.contentTagSelector,
parentIndex: parentIndex,
distanceToParent: ebb.distanceToParent,
nestedProtoView:
isPresent(nestedProtoView) ? resolveInternalDomProtoView(nestedProtoView.render) : null,
componentId: ebb.componentId,
eventLocals: new LiteralArray(ebb.eventBuilder.buildEventLocals()),
localEvents: ebb.eventBuilder.buildLocalEvents(),
globalEvents: ebb.eventBuilder.buildGlobalEvents(),
hostActions: hostActions,
propertySetters: propertySetters,
elementIsEmpty: elementIsEmpty
}));
});
return new api.ProtoViewDto({
render: new DomProtoViewRef(new DomProtoView({
@ -178,7 +177,7 @@ export class ElementBinderBuilder {
bindDirective(directiveIndex: number): DirectiveBuilder {
var directive = new DirectiveBuilder(directiveIndex);
ListWrapper.push(this.directives, directive);
this.directives.push(directive);
return directive;
}
@ -211,12 +210,12 @@ export class ElementBinderBuilder {
}
bindEvent(name, expression, target = null) {
ListWrapper.push(this.eventBindings, this.eventBuilder.add(name, expression, target));
this.eventBindings.push(this.eventBuilder.add(name, expression, target));
}
bindText(index, expression) {
ListWrapper.push(this.textBindingIndices, index);
ListWrapper.push(this.textBindings, expression);
this.textBindingIndices.push(index);
this.textBindings.push(expression);
}
setContentTagSelector(value: string) { this.contentTagSelector = value; }
@ -240,11 +239,11 @@ export class DirectiveBuilder {
}
bindHostAction(actionName: string, actionExpression: string, expression: ASTWithSource) {
ListWrapper.push(this.hostActions, new HostAction(actionName, actionExpression, expression));
this.hostActions.push(new HostAction(actionName, actionExpression, expression));
}
bindEvent(name, expression, target = null) {
ListWrapper.push(this.eventBindings, this.eventBuilder.add(name, expression, target));
this.eventBindings.push(this.eventBuilder.add(name, expression, target));
}
}
@ -266,9 +265,9 @@ export class EventBuilder extends AstTransformer {
fullName, new ASTWithSource(adjustedAst, source.source, source.location));
var event = new Event(name, target, fullName);
if (isBlank(target)) {
ListWrapper.push(this.localEvents, event);
this.localEvents.push(event);
} else {
ListWrapper.push(this.globalEvents, event);
this.globalEvents.push(event);
}
return result;
}
@ -285,7 +284,7 @@ export class EventBuilder extends AstTransformer {
}
if (isEventAccess) {
ListWrapper.push(this.locals, ast);
this.locals.push(ast);
var index = this.locals.length - 1;
return new AccessMember(this._implicitReceiver, `${index}`, (arr) => arr[index], null);
} else {
@ -306,13 +305,13 @@ export class EventBuilder extends AstTransformer {
}
_merge(host: List<Event>, tobeAdded: List<Event>) {
var names = ListWrapper.create();
var names = [];
for (var i = 0; i < host.length; i++) {
ListWrapper.push(names, host[i].fullName);
names.push(host[i].fullName);
}
for (var j = 0; j < tobeAdded.length; j++) {
if (!ListWrapper.contains(names, tobeAdded[j].fullName)) {
ListWrapper.push(host, tobeAdded[j]);
host.push(tobeAdded[j]);
}
}
}