From 545d69aa6df8ea6c2d0712f3c9d02af21e310b90 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Fri, 31 May 2024 05:19:34 -0300 Subject: [PATCH] Use indexOf instead of includes; reset global find regex state --- src/webpack/patchWebpack.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index d728e5a2f..b0f735d2e 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -218,9 +218,11 @@ function patchFactory(id: PropertyKey, factory: ModuleFactory) { const patch = patches[i]; if (patch.predicate && !patch.predicate()) continue; + // indexOf is faster than includes because it doesn't check if searchString is a RegExp + // https://github.com/moonlight-mod/moonlight/blob/53ae39d4010277f49f3b70bebbd27b9cbcdb1c8b/packages/core/src/patch.ts#L61 const moduleMatches = typeof patch.find === "string" - ? code.includes(patch.find) - : patch.find.test(code); + ? code.indexOf(patch.find) !== -1 + : (patch.find.global && (patch.find.lastIndex = 0), patch.find.test(code)); if (!moduleMatches) continue;