refactor(ivy): avoid repeated read of LView from global state (#30587)

PR Close #30587
This commit is contained in:
Pawel Kozlowski 2019-05-21 11:36:22 +02:00 committed by Jason Aden
parent 514ebf402a
commit 2fe6f350cb
1 changed files with 4 additions and 5 deletions

View File

@ -368,11 +368,10 @@ type QueryList_<T> = QueryList<T>& {_valuesTree: any[], _static: boolean};
* @param read What to save in the query
* @returns QueryList<T>
*/
export function query<T>(
function query<T>(
// TODO: "read" should be an AbstractType (FW-486)
predicate: Type<any>| string[], descend: boolean, read: any): QueryList<T> {
lView: LView, predicate: Type<any>| string[], descend: boolean, read: any): QueryList<T> {
ngDevMode && assertPreviousIsParent(getIsParent());
const lView = getLView();
const queryList = new QueryList<T>() as QueryList_<T>;
const queries = lView[QUERIES] || (lView[QUERIES] = new LQueries_(null, null, null));
queryList._valuesTree = [];
@ -443,7 +442,7 @@ export function ɵɵviewQuery<T>(
tView.expandoStartIndex++;
}
const index = getCurrentQueryIndex();
const viewQuery: QueryList<T> = query<T>(predicate, descend, read);
const viewQuery: QueryList<T> = query<T>(lView, predicate, descend, read);
store(index - HEADER_OFFSET, viewQuery);
setCurrentQueryIndex(index + 1);
return viewQuery;
@ -478,7 +477,7 @@ export function ɵɵcontentQuery<T>(
read: any): QueryList<T> {
const lView = getLView();
const tView = lView[TVIEW];
const contentQuery: QueryList<T> = query<T>(predicate, descend, read);
const contentQuery: QueryList<T> = query<T>(lView, predicate, descend, read);
(lView[CONTENT_QUERIES] || (lView[CONTENT_QUERIES] = [])).push(contentQuery);
if (tView.firstTemplatePass) {
const tViewContentQueries = tView.contentQueries || (tView.contentQueries = []);