MCPcopy Index your code
hub / github.com/angular/angular / bloomAdd

Function bloomAdd

packages/core/src/render3/di.ts:152–184  ·  view source on GitHub ↗
(
  injectorIndex: number,
  tView: TView,
  type: ProviderToken<any> | string,
)

Source from the content-addressed store, hash-verified

150 * @param type The directive token to register
151 */
152export function bloomAdd(
153 injectorIndex: number,
154 tView: TView,
155 type: ProviderToken<any> | string,
156): void {
157 ngDevMode && assertEqual(tView.firstCreatePass, true, 'expected firstCreatePass to be true');
158 let id: number | undefined;
159 if (typeof type === 'string') {
160 id = type.charCodeAt(0) || 0;
161 } else if (type.hasOwnProperty(NG_ELEMENT_ID)) {
162 id = (type as any)[NG_ELEMENT_ID];
163 }
164
165 // Set a unique ID on the directive type, so if something tries to inject the directive,
166 // we can easily retrieve the ID and hash it into the bloom bit that should be checked.
167 if (id == null) {
168 id = (type as any)[NG_ELEMENT_ID] = nextNgElementId++;
169 }
170
171 // We only have BLOOM_SIZE (256) slots in our bloom filter (8 buckets * 32 bits each),
172 // so all unique IDs must be modulo-ed into a number from 0 - 255 to fit into the filter.
173 const bloomHash = id & BLOOM_MASK;
174
175 // Create a mask that targets the specific bit associated with the directive.
176 // JS bit operations are 32 bits, so this will be a number between 2^0 and 2^31, corresponding
177 // to bit positions 0 - 31 in a 32 bit integer.
178 const mask = 1 << bloomHash;
179
180 // Each bloom bucket in `tData` represents `BLOOM_BUCKET_BITS` number of bits of `bloomHash`.
181 // Any bits in `bloomHash` beyond `BLOOM_BUCKET_BITS` indicate the bucket offset that the mask
182 // should be written to.
183 (tView.data as number[])[injectorIndex + (bloomHash >> BLOOM_BUCKET_BITS)] |= mask;
184}
185
186/**
187 * Creates (or gets an existing) injector for a given element or container.

Callers 2

di_spec.tsFile · 0.90
diPublicInInjectorFunction · 0.85

Calls 1

assertEqualFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…