From ce2761a2a09527c26a57796a78171be43c68cd59 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 8 Feb 2023 01:06:24 -0500 Subject: [PATCH] Improves splitSingle perf --- src/system/string.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/system/string.ts b/src/system/string.ts index f600afb..f195c19 100644 --- a/src/system/string.ts +++ b/src/system/string.ts @@ -380,9 +380,12 @@ export function splitLast(s: string, splitter: string) { } export function splitSingle(s: string, splitter: string) { - const parts = s.split(splitter, 1); - const first = parts[0]; - return first.length === s.length ? parts : [first, s.substr(first.length + 1)]; + const index = s.indexOf(splitter); + if (index === -1) return [s]; + + const start = s.substring(0, index); + const rest = s.substring(index + splitter.length); + return rest != null ? [start, rest] : [start]; } export function truncate(s: string, truncateTo: number, ellipsis: string = '\u2026', width?: number) {