refactor(ivy): split the memory instruction into store and load (#22268)

PR Close #22268
This commit is contained in:
Victor Berchet
2018-02-16 16:58:07 -08:00
parent 3ceee99e22
commit 5a14e2238f
19 changed files with 105 additions and 114 deletions

View File

@ -65,7 +65,8 @@ export {
t as ɵt,
v as ɵv,
r as ɵr,
m as ɵm,
st as ɵst,
ld as ɵld,
Pp as ɵPp,
} from './render3/index';
// clang-format on

View File

@ -53,7 +53,8 @@ export {
elementStyle as s,
listener as L,
memory as m,
store as st,
load as ld,
projection as P,
projectionDef as pD,

View File

@ -1306,8 +1306,7 @@ export function projection(
const componentNode = findComponentHost(currentView);
// make sure that nodes to project were memorized
const nodesForSelector =
valueInData<LNode[][]>(componentNode.data !.data !, localIndex)[selectorIndex];
const nodesForSelector = componentNode.data !.data ![localIndex][selectorIndex];
// build the linked list of projected nodes:
for (let i = 0; i < nodesForSelector.length; i++) {
@ -1744,23 +1743,20 @@ export function interpolation8(
NO_CHANGE;
}
export function memory<T>(index: number, value?: T): T {
return valueInData<T>(data, index, value);
/** Store a value in the `data` at a given `index`. */
export function store<T>(index: number, value: T): void {
// We don't store any static data for local variables, so the first time
// we see the template, we should store as null to avoid a sparse array
if (index >= tData.length) {
tData[index] = null;
}
data[index] = value;
}
function valueInData<T>(data: any[], index: number, value?: T): T {
if (value === undefined) {
ngDevMode && assertDataInRange(index, data);
value = data[index];
} else {
// We don't store any static data for local variables, so the first time
// we see the template, we should store as null to avoid a sparse array
if (index >= tData.length) {
tData[index] = null;
}
data[index] = value;
}
return value !;
/** Retrieves a value from the `data`. */
export function load<T>(index: number): T {
ngDevMode && assertDataInRange(index, data);
return data[index];
}
export function getCurrentQueries(QueryType: {new (): LQueries}): LQueries {

View File

@ -17,7 +17,7 @@ import {getSymbolIterator} from '../util';
import {assertEqual, assertNotNull} from './assert';
import {ReadFromInjectorFn, getOrCreateNodeInjectorForNode} from './di';
import {assertPreviousIsParent, getCurrentQueries, memory} from './instructions';
import {assertPreviousIsParent, getCurrentQueries, store} from './instructions';
import {DirectiveDef, unusedValueExportToPlacateAjd as unused1} from './interfaces/definition';
import {LInjector, unusedValueExportToPlacateAjd as unused2} from './interfaces/injector';
import {LContainerNode, LElementNode, LNode, LNodeFlags, TNode, unusedValueExportToPlacateAjd as unused3} from './interfaces/node';
@ -389,7 +389,7 @@ export function query<T>(
queries.track(queryList, predicate, descend, read);
if (memoryIndex != null) {
memory(memoryIndex, queryList);
store(memoryIndex, queryList);
}
return queryList;
}