Skip to content

Commit

Permalink
refactor(core): remove several private utils and APIs (#48357)
Browse files Browse the repository at this point in the history
These APIs are no longer used.

PR Close #48357
  • Loading branch information
alan-agius4 authored and AndrewKushnir committed Dec 5, 2022
1 parent a4c82ba commit 0b04da1
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 139 deletions.
6 changes: 0 additions & 6 deletions packages/core/src/render3/assert.ts
Expand Up @@ -73,12 +73,6 @@ export function assertHasParent(tNode: TNode|null) {
assertDefined(tNode!.parent, 'currentTNode should have a parent');
}

export function assertDataNext(lView: LView, index: number, arr?: any[]) {
if (arr == null) arr = lView;
assertEqual(
arr.length, index, `index ${index} expected to be at the end of arr (length ${arr.length})`);
}

export function assertLContainer(value: any): asserts value is LContainer {
assertDefined(value, 'LContainer must be defined');
assertEqual(isLContainer(value), true, 'Expecting LContainer');
Expand Down
8 changes: 0 additions & 8 deletions packages/core/src/render3/namespaces.ts
Expand Up @@ -7,12 +7,4 @@
*/

export const SVG_NAMESPACE = 'svg';
export const SVG_NAMESPACE_URI = 'http://www.w3.org/2000/svg';
export const MATH_ML_NAMESPACE = 'math';
export const MATH_ML_NAMESPACE_URI = 'http://www.w3.org/1998/MathML/';

export function getNamespaceUri(namespace: string): string|null {
const name = namespace.toLowerCase();
return name === SVG_NAMESPACE ? SVG_NAMESPACE_URI :
(name === MATH_ML_NAMESPACE ? MATH_ML_NAMESPACE_URI : null);
}
3 changes: 0 additions & 3 deletions packages/core/src/render3/state.ts
Expand Up @@ -338,9 +338,6 @@ export function isCurrentTNodeParent(): boolean {
export function setCurrentTNodeAsNotParent(): void {
instructionState.lFrame.isParent = false;
}
export function setCurrentTNodeAsParent(): void {
instructionState.lFrame.isParent = true;
}

export function getContextLView(): LView {
const contextLView = instructionState.lFrame.contextLView;
Expand Down
14 changes: 0 additions & 14 deletions packages/core/src/render3/util/view_utils.ts
Expand Up @@ -58,20 +58,6 @@ export function unwrapLView(value: RNode|LView|LContainer): LView|null {
return null;
}

/**
* Returns `LContainer` or `null` if not found.
* @param value wrapped value of `RNode`, `LView`, `LContainer`
*/
export function unwrapLContainer(value: RNode|LView|LContainer): LContainer|null {
while (Array.isArray(value)) {
// This check is same as `isLContainer()` but we don't call at as we don't want to call
// `Array.isArray()` twice and give JITer more work for inlining.
if (value[TYPE] === true) return value as LContainer;
value = value[HOST] as any;
}
return null;
}

/**
* Retrieves an element value from the provided `viewData`, by unwrapping
* from any containers, component views, or style contexts.
Expand Down
54 changes: 0 additions & 54 deletions packages/core/src/util/array_utils.ts
Expand Up @@ -8,18 +8,6 @@

import {assertEqual, assertLessThanOrEqual} from './assert';

/**
* Equivalent to ES6 spread, add each item to an array.
*
* @param items The items to add
* @param arr The array to which you want to add the items
*/
export function addAllToArray(items: any[], arr: any[]) {
for (let i = 0; i < items.length; i++) {
arr.push(items[i]);
}
}

/**
* Determines if the contents of two arrays is identical
*
Expand Down Expand Up @@ -180,48 +168,6 @@ export function arrayInsert2(array: any[], index: number, value1: any, value2: a
}
}

/**
* Insert a `value` into an `array` so that the array remains sorted.
*
* NOTE:
* - Duplicates are not allowed, and are ignored.
* - This uses binary search algorithm for fast inserts.
*
* @param array A sorted array to insert into.
* @param value The value to insert.
* @returns index of the inserted value.
*/
export function arrayInsertSorted(array: string[], value: string): number {
let index = arrayIndexOfSorted(array, value);
if (index < 0) {
// if we did not find it insert it.
index = ~index;
arrayInsert(array, index, value);
}
return index;
}

/**
* Remove `value` from a sorted `array`.
*
* NOTE:
* - This uses binary search algorithm for fast removals.
*
* @param array A sorted array to remove from.
* @param value The value to remove.
* @returns index of the removed value.
* - positive index if value found and removed.
* - negative index if value not found. (`~index` to get the value where it should have been
* inserted)
*/
export function arrayRemoveSorted(array: string[], value: string): number {
const index = arrayIndexOfSorted(array, value);
if (index >= 0) {
arraySplice(array, index, 1);
}
return index;
}


/**
* Get an index of an `value` in a sorted `array`.
Expand Down
55 changes: 1 addition & 54 deletions packages/core/test/util/array_utils_spec.ts
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {arrayIndexOfSorted, arrayInsert, arrayInsert2, arrayInsertSorted, arrayRemoveSorted, arraySplice, flatten, KeyValueArray, keyValueArrayDelete, keyValueArrayGet, keyValueArrayIndexOf, keyValueArraySet} from '../../src/util/array_utils';
import {arrayIndexOfSorted, arrayInsert, arrayInsert2, arraySplice, flatten, KeyValueArray, keyValueArrayDelete, keyValueArrayGet, keyValueArrayIndexOf, keyValueArraySet} from '../../src/util/array_utils';

describe('array_utils', () => {
describe('flatten', () => {
Expand Down Expand Up @@ -76,59 +76,6 @@ describe('array_utils', () => {
});
});

describe('arrayInsertSorted', () => {
it('should insert items don\'t allow duplicates', () => {
let a;
a = ['a', 'c', 'e', 'g', 'i'];
expect(arrayInsertSorted(a, 'a')).toEqual(0);
expect(a).toEqual(['a', 'c', 'e', 'g', 'i']);

a = ['a', 'c', 'e', 'g', 'i'];
expect(arrayInsertSorted(a, 'b')).toEqual(1);
expect(a).toEqual(['a', 'b', 'c', 'e', 'g', 'i']);

a = ['a', 'c', 'e', 'g', 'i'];
expect(arrayInsertSorted(a, 'c')).toEqual(1);
expect(a).toEqual(['a', 'c', 'e', 'g', 'i']);

a = ['a', 'c', 'e', 'g', 'i'];
expect(arrayInsertSorted(a, 'd')).toEqual(2);
expect(a).toEqual(['a', 'c', 'd', 'e', 'g', 'i']);

a = ['a', 'c', 'e', 'g', 'i'];
expect(arrayInsertSorted(a, 'e')).toEqual(2);
expect(a).toEqual(['a', 'c', 'e', 'g', 'i']);
});
});



describe('arrayRemoveSorted', () => {
it('should remove items', () => {
let a;
a = ['a', 'b', 'c', 'd', 'e'];
expect(arrayRemoveSorted(a, 'a')).toEqual(0);
expect(a).toEqual(['b', 'c', 'd', 'e']);

a = ['a', 'b', 'c', 'd', 'e'];
expect(arrayRemoveSorted(a, 'b')).toEqual(1);
expect(a).toEqual(['a', 'c', 'd', 'e']);

a = ['a', 'b', 'c', 'd', 'e'];
expect(arrayRemoveSorted(a, 'c')).toEqual(2);
expect(a).toEqual(['a', 'b', 'd', 'e']);

a = ['a', 'b', 'c', 'd', 'e'];
expect(arrayRemoveSorted(a, 'd')).toEqual(3);
expect(a).toEqual(['a', 'b', 'c', 'e']);

a = ['a', 'b', 'c', 'd', 'e'];
expect(arrayRemoveSorted(a, 'e')).toEqual(4);
expect(a).toEqual(['a', 'b', 'c', 'd']);
});
});


describe('arrayIndexOfSorted', () => {
it('should get index of', () => {
const a = ['a', 'b', 'c', 'd', 'e'];
Expand Down

0 comments on commit 0b04da1

Please sign in to comment.