refactor(ivy): avoid calling query instructions from static query instructions (#30587)
PR Close #30587
This commit is contained in:
parent
2fe6f350cb
commit
b613f90146
|
@ -24,7 +24,7 @@ import {unusedValueExportToPlacateAjd as unused1} from './interfaces/definition'
|
||||||
import {unusedValueExportToPlacateAjd as unused2} from './interfaces/injector';
|
import {unusedValueExportToPlacateAjd as unused2} from './interfaces/injector';
|
||||||
import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType, unusedValueExportToPlacateAjd as unused3} from './interfaces/node';
|
import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType, unusedValueExportToPlacateAjd as unused3} from './interfaces/node';
|
||||||
import {LQueries, unusedValueExportToPlacateAjd as unused4} from './interfaces/query';
|
import {LQueries, unusedValueExportToPlacateAjd as unused4} from './interfaces/query';
|
||||||
import {CONTENT_QUERIES, HEADER_OFFSET, LView, QUERIES, TVIEW} from './interfaces/view';
|
import {CONTENT_QUERIES, HEADER_OFFSET, LView, QUERIES, TVIEW, TView} from './interfaces/view';
|
||||||
import {getCurrentQueryIndex, getIsParent, getLView, isCreationMode, setCurrentQueryIndex} from './state';
|
import {getCurrentQueryIndex, getIsParent, getLView, isCreationMode, setCurrentQueryIndex} from './state';
|
||||||
import {loadInternal} from './util/view_utils';
|
import {loadInternal} from './util/view_utils';
|
||||||
import {createElementRef, createTemplateRef} from './view_engine_compatibility';
|
import {createElementRef, createTemplateRef} from './view_engine_compatibility';
|
||||||
|
@ -370,12 +370,13 @@ type QueryList_<T> = QueryList<T>& {_valuesTree: any[], _static: boolean};
|
||||||
*/
|
*/
|
||||||
function query<T>(
|
function query<T>(
|
||||||
// TODO: "read" should be an AbstractType (FW-486)
|
// TODO: "read" should be an AbstractType (FW-486)
|
||||||
lView: LView, predicate: Type<any>| string[], descend: boolean, read: any): QueryList<T> {
|
lView: LView, predicate: Type<any>| string[], descend: boolean, read: any,
|
||||||
|
isStatic: boolean): QueryList<T> {
|
||||||
ngDevMode && assertPreviousIsParent(getIsParent());
|
ngDevMode && assertPreviousIsParent(getIsParent());
|
||||||
const queryList = new QueryList<T>() as QueryList_<T>;
|
const queryList = new QueryList<T>() as QueryList_<T>;
|
||||||
const queries = lView[QUERIES] || (lView[QUERIES] = new LQueries_(null, null, null));
|
const queries = lView[QUERIES] || (lView[QUERIES] = new LQueries_(null, null, null));
|
||||||
queryList._valuesTree = [];
|
queryList._valuesTree = [];
|
||||||
queryList._static = false;
|
queryList._static = isStatic;
|
||||||
queries.track(queryList, predicate, descend, read);
|
queries.track(queryList, predicate, descend, read);
|
||||||
storeCleanupWithContext(lView, queryList, queryList.destroy);
|
storeCleanupWithContext(lView, queryList, queryList.destroy);
|
||||||
return queryList;
|
return queryList;
|
||||||
|
@ -415,13 +416,11 @@ export function ɵɵqueryRefresh(queryList: QueryList<any>): boolean {
|
||||||
export function ɵɵstaticViewQuery<T>(
|
export function ɵɵstaticViewQuery<T>(
|
||||||
// TODO(FW-486): "read" should be an AbstractType
|
// TODO(FW-486): "read" should be an AbstractType
|
||||||
predicate: Type<any>| string[], descend: boolean, read: any): void {
|
predicate: Type<any>| string[], descend: boolean, read: any): void {
|
||||||
const queryList = ɵɵviewQuery(predicate, descend, read) as QueryList_<T>;
|
const lView = getLView();
|
||||||
const tView = getLView()[TVIEW];
|
const tView = lView[TVIEW];
|
||||||
queryList._static = true;
|
viewQueryInternal(lView, tView, predicate, descend, read, true);
|
||||||
if (!tView.staticViewQueries) {
|
|
||||||
tView.staticViewQueries = true;
|
tView.staticViewQueries = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new QueryList, stores the reference in LView and returns QueryList.
|
* Creates new QueryList, stores the reference in LView and returns QueryList.
|
||||||
|
@ -438,14 +437,20 @@ export function ɵɵviewQuery<T>(
|
||||||
predicate: Type<any>| string[], descend: boolean, read: any): QueryList<T> {
|
predicate: Type<any>| string[], descend: boolean, read: any): QueryList<T> {
|
||||||
const lView = getLView();
|
const lView = getLView();
|
||||||
const tView = lView[TVIEW];
|
const tView = lView[TVIEW];
|
||||||
|
return viewQueryInternal(lView, tView, predicate, descend, read, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function viewQueryInternal<T>(
|
||||||
|
lView: LView, tView: TView, predicate: Type<any>| string[], descend: boolean, read: any,
|
||||||
|
isStatic: boolean): QueryList<T> {
|
||||||
if (tView.firstTemplatePass) {
|
if (tView.firstTemplatePass) {
|
||||||
tView.expandoStartIndex++;
|
tView.expandoStartIndex++;
|
||||||
}
|
}
|
||||||
const index = getCurrentQueryIndex();
|
const index = getCurrentQueryIndex();
|
||||||
const viewQuery: QueryList<T> = query<T>(lView, predicate, descend, read);
|
const queryList: QueryList<T> = query<T>(lView, predicate, descend, read, isStatic);
|
||||||
store(index - HEADER_OFFSET, viewQuery);
|
store(index - HEADER_OFFSET, queryList);
|
||||||
setCurrentQueryIndex(index + 1);
|
setCurrentQueryIndex(index + 1);
|
||||||
return viewQuery;
|
return queryList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -477,7 +482,15 @@ export function ɵɵcontentQuery<T>(
|
||||||
read: any): QueryList<T> {
|
read: any): QueryList<T> {
|
||||||
const lView = getLView();
|
const lView = getLView();
|
||||||
const tView = lView[TVIEW];
|
const tView = lView[TVIEW];
|
||||||
const contentQuery: QueryList<T> = query<T>(lView, predicate, descend, read);
|
return contentQueryInternal(lView, tView, directiveIndex, predicate, descend, read, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function contentQueryInternal<T>(
|
||||||
|
lView: LView, tView: TView, directiveIndex: number, predicate: Type<any>| string[],
|
||||||
|
descend: boolean,
|
||||||
|
// TODO(FW-486): "read" should be an AbstractType
|
||||||
|
read: any, isStatic: boolean): QueryList<T> {
|
||||||
|
const contentQuery: QueryList<T> = query<T>(lView, predicate, descend, read, isStatic);
|
||||||
(lView[CONTENT_QUERIES] || (lView[CONTENT_QUERIES] = [])).push(contentQuery);
|
(lView[CONTENT_QUERIES] || (lView[CONTENT_QUERIES] = [])).push(contentQuery);
|
||||||
if (tView.firstTemplatePass) {
|
if (tView.firstTemplatePass) {
|
||||||
const tViewContentQueries = tView.contentQueries || (tView.contentQueries = []);
|
const tViewContentQueries = tView.contentQueries || (tView.contentQueries = []);
|
||||||
|
@ -506,13 +519,11 @@ export function ɵɵstaticContentQuery<T>(
|
||||||
directiveIndex: number, predicate: Type<any>| string[], descend: boolean,
|
directiveIndex: number, predicate: Type<any>| string[], descend: boolean,
|
||||||
// TODO(FW-486): "read" should be an AbstractType
|
// TODO(FW-486): "read" should be an AbstractType
|
||||||
read: any): void {
|
read: any): void {
|
||||||
const queryList = ɵɵcontentQuery(directiveIndex, predicate, descend, read) as QueryList_<T>;
|
const lView = getLView();
|
||||||
const tView = getLView()[TVIEW];
|
const tView = lView[TVIEW];
|
||||||
queryList._static = true;
|
contentQueryInternal(lView, tView, directiveIndex, predicate, descend, read, true);
|
||||||
if (!tView.staticContentQueries) {
|
|
||||||
tView.staticContentQueries = true;
|
tView.staticContentQueries = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue