perf(ivy): minor cleanup; prevent sparse arrays (#30495)

PR Close #30495
This commit is contained in:
Miško Hevery 2019-05-15 16:24:29 -07:00 committed by Jason Aden
parent e946594bf8
commit df1d3fbd7b
3 changed files with 8 additions and 5 deletions

View File

@ -9,6 +9,7 @@
import {assertDataInRange} from '../../util/assert'; import {assertDataInRange} from '../../util/assert';
import {isObservable} from '../../util/lang'; import {isObservable} from '../../util/lang';
import {EMPTY_OBJ} from '../empty';
import {PropertyAliasValue, TNode, TNodeFlags, TNodeType} from '../interfaces/node'; import {PropertyAliasValue, TNode, TNodeFlags, TNodeType} from '../interfaces/node';
import {GlobalTargetResolver, RElement, Renderer3, isProceduralRenderer} from '../interfaces/renderer'; import {GlobalTargetResolver, RElement, Renderer3, isProceduralRenderer} from '../interfaces/renderer';
import {CLEANUP, FLAGS, LView, LViewFlags, RENDERER, TVIEW} from '../interfaces/view'; import {CLEANUP, FLAGS, LView, LViewFlags, RENDERER, TVIEW} from '../interfaces/view';
@ -115,7 +116,7 @@ function listenerInternal(
// add native event listener - applicable to elements only // add native event listener - applicable to elements only
if (tNode.type === TNodeType.Element) { if (tNode.type === TNodeType.Element) {
const native = getNativeByTNode(tNode, lView) as RElement; const native = getNativeByTNode(tNode, lView) as RElement;
const resolved = eventTargetResolver ? eventTargetResolver(native) : {} as any; const resolved = eventTargetResolver ? eventTargetResolver(native) : EMPTY_OBJ as any;
const target = resolved.target || native; const target = resolved.target || native;
const renderer = loadRendererFn ? loadRendererFn(tNode, lView) : lView[RENDERER]; const renderer = loadRendererFn ? loadRendererFn(tNode, lView) : lView[RENDERER];
const lCleanup = getCleanup(lView); const lCleanup = getCleanup(lView);

View File

@ -1322,7 +1322,10 @@ function setInputsFromAttrs<T>(
function generateInitialInputs( function generateInitialInputs(
directiveIndex: number, inputs: {[key: string]: string}, tNode: TNode): InitialInputData { directiveIndex: number, inputs: {[key: string]: string}, tNode: TNode): InitialInputData {
const initialInputData: InitialInputData = tNode.initialInputs || (tNode.initialInputs = []); const initialInputData: InitialInputData = tNode.initialInputs || (tNode.initialInputs = []);
initialInputData[directiveIndex] = null; // Ensure that we don't create sparse arrays
for (let i = initialInputData.length; i <= directiveIndex; i++) {
initialInputData.push(null);
}
const attrs = tNode.attrs !; const attrs = tNode.attrs !;
let i = 0; let i = 0;

View File

@ -330,10 +330,9 @@ function add(
function addMatch(query: LQuery<any>, matchingValue: any, insertBeforeViewMatches: boolean): void { function addMatch(query: LQuery<any>, matchingValue: any, insertBeforeViewMatches: boolean): void {
// Views created in constructors may have their container values created too early. In this case, // Views created in constructors may have their container values created too early. In this case,
// ensure template node results are spliced before container results. Otherwise, results inside // ensure template node results are unshifted before container results. Otherwise, results inside
// embedded views will appear before results on parent template nodes when flattened. // embedded views will appear before results on parent template nodes when flattened.
insertBeforeViewMatches ? query.values.splice(-1, 0, matchingValue) : insertBeforeViewMatches ? query.values.unshift(matchingValue) : query.values.push(matchingValue);
query.values.push(matchingValue);
query.list.setDirty(); query.list.setDirty();
} }