Browse Source

Perf: minor optimization reducing array allocation

SukkaW 1 year ago
parent
commit
eabac5bfce
2 changed files with 2 additions and 2 deletions
  1. 1 1
      Build/build-common.ts
  2. 1 1
      Build/lib/writing-strategy/surge.ts

+ 1 - 1
Build/build-common.ts

@@ -104,7 +104,7 @@ async function transform(parentSpan: Span, sourcePath: string, relativePath: str
   return parentSpan
     .traceChild(`transform ruleset: ${id}`)
     .traceAsyncFn(async (span) => {
-      const type = relativePath.split(path.sep)[0];
+      const type = relativePath.slice(0, relativePath.indexOf(path.sep));
 
       if (type !== 'ip' && type !== 'non_ip' && type !== 'domainset') {
         throw new TypeError(`Invalid type: ${type}`);

+ 1 - 1
Build/lib/writing-strategy/surge.ts

@@ -194,7 +194,7 @@ export class SurgeMitmSgmodule extends BaseWriteStrategy {
         urlRegex = urlRegex.slice(9);
       }
 
-      const potentialHostname = urlRegex.split('/')[0]
+      const potentialHostname = urlRegex.slice(0, urlRegex.indexOf('/'))
         // pre process regex
         .replaceAll(String.raw`\.`, '.')
         .replaceAll('.+', '*')