From 84f1d073c89095667f972e40c9cda83a2c3cc7eb Mon Sep 17 00:00:00 2001 From: Mikhail Bodrov Date: Wed, 3 Jul 2019 17:44:17 +0300 Subject: [PATCH] Optimize slice last sharp tail (#7353) --- src/cli/commands/list.js | 2 +- src/hoisted-tree-builder.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli/commands/list.js b/src/cli/commands/list.js index b9b5a8a0ef..b64936e7e7 100644 --- a/src/cli/commands/list.js +++ b/src/cli/commands/list.js @@ -152,7 +152,7 @@ export async function buildTree( } export function getParent(key: string, treesByKey: Object): Object { - const parentKey = key.split('#').slice(0, -1).join('#'); + const parentKey = key.slice(0, key.lastIndexOf('#')); return treesByKey[parentKey]; } diff --git a/src/hoisted-tree-builder.js b/src/hoisted-tree-builder.js index e8f1b2c50a..b24ea72c59 100644 --- a/src/hoisted-tree-builder.js +++ b/src/hoisted-tree-builder.js @@ -15,7 +15,7 @@ export type HoistedTree = { export type HoistedTrees = Array; export function getParent(key: string, treesByKey: Object): Object { - const parentKey = key.split('#').slice(0, -1).join('#'); + const parentKey = key.slice(0, key.lastIndexOf('#')); return treesByKey[parentKey]; }