diff --git a/packages/core/src/createRenderer.ts b/packages/core/src/createRenderer.ts index ce130caa..4c8ebb4f 100644 --- a/packages/core/src/createRenderer.ts +++ b/packages/core/src/createRenderer.ts @@ -1,7 +1,7 @@ import { autorun, stop } from '@vue/observer' import { queueJob } from '@vue/scheduler' import { VNodeFlags, ChildrenFlags } from './flags' -import { EMPTY_OBJ, isReservedProp } from './utils' +import { EMPTY_OBJ, isReservedProp, lis } from './utils' import { VNode, MountedVNode, @@ -1058,52 +1058,6 @@ export function createRenderer(options: RendererOptions) { } } - // https://en.wikipedia.org/wiki/Longest_increasing_subsequence - function lis(arr: number[]): number[] { - const p = arr.slice() - const result = [0] - let i - let j - let u - let v - let c - const len = arr.length - for (i = 0; i < len; i++) { - const arrI = arr[i] - if (arrI !== 0) { - j = result[result.length - 1] - if (arr[j] < arrI) { - p[i] = j - result.push(i) - continue - } - u = 0 - v = result.length - 1 - while (u < v) { - c = ((u + v) / 2) | 0 - if (arr[result[c]] < arrI) { - u = c + 1 - } else { - v = c - } - } - if (arrI < arr[result[u]]) { - if (u > 0) { - p[i] = result[u - 1] - } - result[u] = i - } - } - } - u = result.length - v = result[u - 1] - while (u-- > 0) { - result[u] = v - v = p[v] - } - return result - } - // unmounting ---------------------------------------------------------------- function unmount(vnode: VNode) { diff --git a/packages/core/src/utils.ts b/packages/core/src/utils.ts index 465c0d9b..e0605d5d 100644 --- a/packages/core/src/utils.ts +++ b/packages/core/src/utils.ts @@ -10,3 +10,49 @@ export const isReservedProp = (key: string): boolean => { return key.startsWith('nativeOn') } } + +// https://en.wikipedia.org/wiki/Longest_increasing_subsequence +export function lis(arr: number[]): number[] { + const p = arr.slice() + const result = [0] + let i + let j + let u + let v + let c + const len = arr.length + for (i = 0; i < len; i++) { + const arrI = arr[i] + if (arrI !== 0) { + j = result[result.length - 1] + if (arr[j] < arrI) { + p[i] = j + result.push(i) + continue + } + u = 0 + v = result.length - 1 + while (u < v) { + c = ((u + v) / 2) | 0 + if (arr[result[c]] < arrI) { + u = c + 1 + } else { + v = c + } + } + if (arrI < arr[result[u]]) { + if (u > 0) { + p[i] = result[u - 1] + } + result[u] = i + } + } + } + u = result.length + v = result[u - 1] + while (u-- > 0) { + result[u] = v + v = p[v] + } + return result +}