Skip to content

Commit 8e8c1ad

Browse files
pkozlowski-opensourcematsko
authored andcommitted
refactor(ivy): name LQuery object for easier memory allocation tracking (angular#30656)
PR Close angular#30656
1 parent b617849 commit 8e8c1ad

File tree

1 file changed

+34
-52
lines changed

1 file changed

+34
-52
lines changed

packages/core/src/render3/query.ts

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -58,35 +58,35 @@ export interface QueryPredicate<T> {
5858
* - values collected based on a predicate
5959
* - `QueryList` to which collected values should be reported
6060
*/
61-
export interface LQuery<T> {
62-
/**
63-
* Next query. Used when queries are stored as a linked list in `LQueries`.
64-
*/
65-
next: LQuery<any>|null;
66-
67-
/**
68-
* Destination to which the value should be added.
69-
*/
70-
list: QueryList<T>;
71-
72-
/**
73-
* A predicate which determines if a given element/directive should be included in the query
74-
* results.
75-
*/
76-
predicate: QueryPredicate<T>;
77-
78-
/**
79-
* Values which have been located.
80-
*
81-
* This is what builds up the `QueryList._valuesTree`.
82-
*/
83-
values: any[];
84-
85-
/**
86-
* A pointer to an array that stores collected values from views. This is necessary so we know a
87-
* container into which to insert nodes collected from views.
88-
*/
89-
containerValues: any[]|null;
61+
class LQuery<T> {
62+
constructor(
63+
/**
64+
* Next query. Used when queries are stored as a linked list in `LQueries`.
65+
*/
66+
public next: LQuery<any>|null,
67+
68+
/**
69+
* Destination to which the value should be added.
70+
*/
71+
public list: QueryList<T>,
72+
73+
/**
74+
* A predicate which determines if a given element/directive should be included in the query
75+
* results.
76+
*/
77+
public predicate: QueryPredicate<T>,
78+
79+
/**
80+
* Values which have been located.
81+
* This is what builds up the `QueryList._valuesTree`.
82+
*/
83+
public values: any[],
84+
85+
/**
86+
* A pointer to an array that stores collected values from views. This is necessary so we
87+
* know a container into which to insert nodes collected from views.
88+
*/
89+
public containerValues: any[]|null) {}
9090
}
9191

9292
export class LQueries_ implements LQueries {
@@ -145,14 +145,7 @@ function copyQueriesToContainer(query: LQuery<any>| null): LQuery<any>|null {
145145
while (query) {
146146
const containerValues: any[] = []; // prepare room for views
147147
query.values.push(containerValues);
148-
const clonedQuery: LQuery<any> = {
149-
next: result,
150-
list: query.list,
151-
predicate: query.predicate,
152-
values: containerValues,
153-
containerValues: null
154-
};
155-
result = clonedQuery;
148+
result = new LQuery<any>(result, query.list, query.predicate, containerValues, null);
156149
query = query.next;
157150
}
158151

@@ -163,14 +156,7 @@ function copyQueriesToView(query: LQuery<any>| null): LQuery<any>|null {
163156
let result: LQuery<any>|null = null;
164157

165158
while (query) {
166-
const clonedQuery: LQuery<any> = {
167-
next: result,
168-
list: query.list,
169-
predicate: query.predicate,
170-
values: [],
171-
containerValues: query.values
172-
};
173-
result = clonedQuery;
159+
result = new LQuery<any>(result, query.list, query.predicate, [], query.values);
174160
query = query.next;
175161
}
176162

@@ -349,13 +335,9 @@ function createPredicate<T>(predicate: Type<T>| string[], read: Type<T>| null):
349335
function createLQuery<T>(
350336
previous: LQuery<any>| null, queryList: QueryList<T>, predicate: Type<T>| string[],
351337
read: Type<T>| null): LQuery<T> {
352-
return {
353-
next: previous,
354-
list: queryList,
355-
predicate: createPredicate(predicate, read),
356-
values: (queryList as any as QueryList_<T>)._valuesTree,
357-
containerValues: null
358-
};
338+
return new LQuery(
339+
previous, queryList, createPredicate(predicate, read),
340+
(queryList as any as QueryList_<T>)._valuesTree, null);
359341
}
360342

361343
type QueryList_<T> = QueryList<T>& {_valuesTree: any[], _static: boolean};

0 commit comments

Comments
 (0)