refactor(ivy): flatten LInjector into LViewData (#26220)
PR Close #26220
This commit is contained in:

committed by
Alex Rickabaugh

parent
cb59d87489
commit
730679964f
@ -7,71 +7,97 @@
|
||||
*/
|
||||
|
||||
|
||||
import {ChangeDetectorRef} from '../../change_detection/change_detector_ref';
|
||||
import {ElementRef} from '../../linker/element_ref';
|
||||
import {TemplateRef} from '../../linker/template_ref';
|
||||
import {ViewContainerRef} from '../../linker/view_container_ref';
|
||||
|
||||
import {TContainerNode, TElementContainerNode, TElementNode,} from './node';
|
||||
import {LViewData} from './view';
|
||||
|
||||
export interface LInjector {
|
||||
/**
|
||||
* We need to store a reference to the injector's parent so DI can keep looking up
|
||||
* the injector tree until it finds the dependency it's looking for.
|
||||
*/
|
||||
readonly parent: LInjector|null;
|
||||
export const TNODE = 8;
|
||||
export const PARENT_INJECTOR = 8;
|
||||
export const INJECTOR_SIZE = 9;
|
||||
|
||||
/** Necessary to find directive indices for a particular node and look up the LNode. */
|
||||
readonly tNode: TElementNode|TElementContainerNode|TContainerNode;
|
||||
|
||||
/**
|
||||
* The view where the node is stored. Necessary because as we traverse up the injector
|
||||
* tree the view where we search directives may change.
|
||||
*/
|
||||
readonly view: LViewData;
|
||||
|
||||
/**
|
||||
* The following bloom filter determines whether a directive is available
|
||||
* on the associated node or not. This prevents us from searching the directives
|
||||
* array at this level unless it's probable the directive is in it.
|
||||
*
|
||||
* - bf0: Check directive IDs 0-31 (IDs are % 128)
|
||||
* - bf1: Check directive IDs 32-63
|
||||
* - bf2: Check directive IDs 64-95
|
||||
* - bf3: Check directive IDs 96-127
|
||||
* - bf4: Check directive IDs 128-159
|
||||
* - bf5: Check directive IDs 160 - 191
|
||||
* - bf6: Check directive IDs 192 - 223
|
||||
* - bf7: Check directive IDs 224 - 255
|
||||
*
|
||||
* See: https://en.wikipedia.org/wiki/Bloom_filter for more about bloom filters.
|
||||
*/
|
||||
bf0: number;
|
||||
bf1: number;
|
||||
bf2: number;
|
||||
bf3: number;
|
||||
bf4: number;
|
||||
bf5: number;
|
||||
bf6: number;
|
||||
bf7: number;
|
||||
|
||||
/**
|
||||
* cbf0 - cbf7 properties determine whether a directive is available through a
|
||||
* parent injector. They refer to the merged values of parent bloom filters. This
|
||||
* allows us to skip looking up the chain unless it's probable that directive exists
|
||||
* up the chain.
|
||||
*/
|
||||
cbf0: number;
|
||||
cbf1: number;
|
||||
cbf2: number;
|
||||
cbf3: number;
|
||||
cbf4: number;
|
||||
cbf5: number;
|
||||
cbf6: number;
|
||||
cbf7: number;
|
||||
export const enum InjectorLocationFlags {
|
||||
InjectorIndexMask = 0b111111111111111,
|
||||
ViewOffsetShift = 15
|
||||
}
|
||||
|
||||
/**
|
||||
* Each injector is saved in 9 contiguous slots in `LViewData` and 9 contiguous slots in
|
||||
* `TView.data`. This allows us to store information about the current node's tokens (which
|
||||
* can be shared in `TView`) as well as the tokens of its ancestor nodes (which cannot be
|
||||
* shared, so they live in `LViewData`).
|
||||
*
|
||||
* Each of these slots (aside from the last slot) contains a bloom filter. This bloom filter
|
||||
* determines whether a directive is available on the associated node or not. This prevents us
|
||||
* from searching the directives array at this level unless it's probable the directive is in it.
|
||||
*
|
||||
* See: https://en.wikipedia.org/wiki/Bloom_filter for more about bloom filters.
|
||||
*
|
||||
* Because all injectors have been flattened into `LViewData` and `TViewData`, they cannot typed
|
||||
* using interfaces as they were previously. The start index of each `LInjector` and `TInjector`
|
||||
* will differ based on where it is flattened into the main array, so it's not possible to know
|
||||
* the indices ahead of time and save their types here. The interfaces are still included here
|
||||
* for documentation purposes.
|
||||
*
|
||||
* export interface LInjector extends Array<any> {
|
||||
*
|
||||
* // Cumulative bloom for directive IDs 0-31 (IDs are % BLOOM_SIZE)
|
||||
* [0]: number;
|
||||
*
|
||||
* // Cumulative bloom for directive IDs 32-63
|
||||
* [1]: number;
|
||||
*
|
||||
* // Cumulative bloom for directive IDs 64-95
|
||||
* [2]: number;
|
||||
*
|
||||
* // Cumulative bloom for directive IDs 96-127
|
||||
* [3]: number;
|
||||
*
|
||||
* // Cumulative bloom for directive IDs 128-159
|
||||
* [4]: number;
|
||||
*
|
||||
* // Cumulative bloom for directive IDs 160 - 191
|
||||
* [5]: number;
|
||||
*
|
||||
* // Cumulative bloom for directive IDs 192 - 223
|
||||
* [6]: number;
|
||||
*
|
||||
* // Cumulative bloom for directive IDs 224 - 255
|
||||
* [7]: number;
|
||||
*
|
||||
* // We need to store a reference to the injector's parent so DI can keep looking up
|
||||
* // the injector tree until it finds the dependency it's looking for.
|
||||
* [PARENT_INJECTOR]: number;
|
||||
* }
|
||||
*
|
||||
* export interface TInjector extends Array<any> {
|
||||
*
|
||||
* // Shared node bloom for directive IDs 0-31 (IDs are % BLOOM_SIZE)
|
||||
* [0]: number;
|
||||
*
|
||||
* // Shared node bloom for directive IDs 32-63
|
||||
* [1]: number;
|
||||
*
|
||||
* // Shared node bloom for directive IDs 64-95
|
||||
* [2]: number;
|
||||
*
|
||||
* // Shared node bloom for directive IDs 96-127
|
||||
* [3]: number;
|
||||
*
|
||||
* // Shared node bloom for directive IDs 128-159
|
||||
* [4]: number;
|
||||
*
|
||||
* // Shared node bloom for directive IDs 160 - 191
|
||||
* [5]: number;
|
||||
*
|
||||
* // Shared node bloom for directive IDs 192 - 223
|
||||
* [6]: number;
|
||||
*
|
||||
* // Shared node bloom for directive IDs 224 - 255
|
||||
* [7]: number;
|
||||
*
|
||||
* // Necessary to find directive indices for a particular node.
|
||||
* [TNODE]: TElementNode|TElementContainerNode|TContainerNode;
|
||||
* }
|
||||
*/
|
||||
|
||||
// Note: This hack is necessary so we don't erroneously get a circular dependency
|
||||
// failure based on types.
|
||||
export const unusedValueExportToPlacateAjd = 1;
|
||||
|
@ -7,8 +7,6 @@
|
||||
*/
|
||||
|
||||
import {LContainer} from './container';
|
||||
import {LInjector} from './injector';
|
||||
import {LQueries} from './query';
|
||||
import {RComment, RElement, RText} from './renderer';
|
||||
import {StylingContext} from './styling';
|
||||
import {LViewData, TView} from './view';
|
||||
|
@ -550,11 +550,15 @@ export type HookData = (number | (() => void))[];
|
||||
* Static data that corresponds to the instance-specific data array on an LView.
|
||||
*
|
||||
* Each node's static data is stored in tData at the same index that it's stored
|
||||
* in the data array. Each pipe's definition is stored here at the same index
|
||||
* as its pipe instance in the data array. Any nodes that do not have static
|
||||
* data store a null value in tData to avoid a sparse array.
|
||||
* in the data array. Any nodes that do not have static data store a null value in
|
||||
* tData to avoid a sparse array.
|
||||
*
|
||||
* Each pipe's definition is stored here at the same index as its pipe instance in
|
||||
* the data array.
|
||||
*
|
||||
* Injector bloom filters are also stored here.
|
||||
*/
|
||||
export type TData = (TNode | PipeDefInternal<any>| null)[];
|
||||
export type TData = (TNode | PipeDefInternal<any>| number | null)[];
|
||||
|
||||
/** Type for TView.currentMatches */
|
||||
export type CurrentMatchesList = [DirectiveDefInternal<any>, (string | number | null)];
|
||||
|
Reference in New Issue
Block a user