From 147f1de9e4e944f4446c01a331a9c07f2aa63377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20=C3=98yst=C3=A5=20Lloyd?= Date: Tue, 9 May 2023 17:35:06 +0200 Subject: [PATCH] Improved performance --- .../tailwindcss-language-service/src/util/find.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/tailwindcss-language-service/src/util/find.ts b/packages/tailwindcss-language-service/src/util/find.ts index 7d67cb85..3715ee26 100644 --- a/packages/tailwindcss-language-service/src/util/find.ts +++ b/packages/tailwindcss-language-service/src/util/find.ts @@ -14,12 +14,18 @@ import { getTextWithoutComments } from './doc' import { isSemicolonlessCssLanguage } from './languages' export function findAll(re: RegExp, str: string): RegExpMatchArray[] { - let match: RegExpMatchArray - let matches: RegExpMatchArray[] = [] + let match: RegExpMatchArray; + + const count = (str.match(re) || []).length; + let matches: RegExpMatchArray[] = new Array(count); + let i = 0; + while ((match = re.exec(str)) !== null) { - matches.push({ ...match }) + matches[i] = match; + i++; } - return matches + + return matches; } export function findLast(re: RegExp, str: string): RegExpMatchArray {