Skip to content

Commit 7efc52b

Browse files
committed
Minor optimizations for chrome engine
1 parent 74a99da commit 7efc52b

1 file changed

Lines changed: 19 additions & 51 deletions

File tree

src/core/ProxyEngineChrome.ts

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ function FindProxyForURL(url, host, noDiagnostics) {
113113
if (activeProfileType == SmartProfileType.SystemProxy)
114114
return resultSystem;
115115
116-
if (activeProfileType == SmartProfileType.Direct)
116+
if (activeProfileType == SmartProfileType.Direct || !host)
117117
return resultDirect;
118118
119-
host = host?.toLowerCase();
119+
host = host.toLowerCase();
120120
121121
// applying ProxyPerOrigin
122122
// is not applicable for Chromium
@@ -229,9 +229,6 @@ function findMatchedUrlInRules(searchUrl, host, hostAndPort, rules) {
229229
switch (rule.compiledRuleType) {
230230
case CompiledProxyRuleType.SearchDomainSubdomain:
231231
232-
if (host == null) {
233-
continue;
234-
}
235232
// domain
236233
if (host == rule.search)
237234
return rule;
@@ -249,10 +246,7 @@ function findMatchedUrlInRules(searchUrl, host, hostAndPort, rules) {
249246
break;
250247
251248
case CompiledProxyRuleType.RegexHost:
252-
if (host == null) {
253-
continue;
254-
}
255-
249+
256250
if (rule.regex.test(host))
257251
return rule;
258252
break;
@@ -271,46 +265,35 @@ function findMatchedUrlInRules(searchUrl, host, hostAndPort, rules) {
271265
272266
case CompiledProxyRuleType.SearchDomain:
273267
274-
if (host == null) {
275-
continue;
276-
}
277268
if (rule.search == host)
278269
return rule;
279270
break;
280271
281272
case CompiledProxyRuleType.SearchDomainAndPath:
282273
283-
if (schemaLessUrlLowerCase == null) {
284-
schemaLessUrlLowerCase = removeSchemaFromUrl(lowerCaseUrl);
285-
if (schemaLessUrlLowerCase == null) {
286-
continue;
287-
}
288-
}
274+
schemaLessUrlLowerCase ??= removeSchemaFromUrl(lowerCaseUrl);
275+
if (schemaLessUrlLowerCase == null)
276+
continue;
277+
289278
if (schemaLessUrlLowerCase.startsWith(rule.search))
290279
return rule;
291280
292281
break;
293282
294283
case CompiledProxyRuleType.SearchDomainSubdomainAndPath:
295284
{
296-
if (schemaLessUrlLowerCase == null) {
297-
schemaLessUrlLowerCase = removeSchemaFromUrl(lowerCaseUrl);
298-
if (schemaLessUrlLowerCase == null) {
299-
continue;
300-
}
301-
}
285+
schemaLessUrlLowerCase ??= removeSchemaFromUrl(lowerCaseUrl);
286+
if (schemaLessUrlLowerCase == null)
287+
continue;
288+
302289
if (schemaLessUrlLowerCase.startsWith(rule.search))
303290
return rule;
304291
305-
let ruleSearchHost = extractHostFromInvalidUrl(rule.search);
306-
if (ruleSearchHost != null) {
307-
308-
if (host == null) {
309-
continue;
310-
}
292+
rule.searchHost ??= extractHostFromInvalidUrl(rule.search);
293+
if (rule.searchHost != null) {
311294
312295
// should be the same
313-
if (ruleSearchHost != host && !host.endsWith('.' + ruleSearchHost))
296+
if (rule.searchHost != host && !host.endsWith('.' + rule.searchHost))
314297
continue;
315298
316299
// after this state, we are sure that the url is for the same domain, now just checking the path
@@ -335,28 +318,19 @@ function findMatchedUrlInRules(searchUrl, host, hostAndPort, rules) {
335318
switch (rule.compiledRuleType) {
336319
337320
case CompiledProxyRuleType.RegexHost:
338-
if (host == null) {
339-
continue;
340-
}
341321
342322
if (rule.regex.test(host))
343323
return rule;
344324
break;
345325
346326
case CompiledProxyRuleType.SearchDomain:
347327
348-
if (host == null) {
349-
continue;
350-
}
351328
if (rule.search == host)
352329
return rule;
353330
break;
354331
355332
case CompiledProxyRuleType.SearchDomainSubdomain:
356333
357-
if (host == null) {
358-
continue;
359-
}
360334
// domain
361335
if (host == rule.search)
362336
return rule;
@@ -369,24 +343,18 @@ function findMatchedUrlInRules(searchUrl, host, hostAndPort, rules) {
369343
370344
case CompiledProxyRuleType.SearchDomainSubdomainAndPath:
371345
{
346+
schemaLessUrlLowerCase ??= removeSchemaFromUrl(lowerCaseUrl);
372347
if (schemaLessUrlLowerCase == null) {
373-
schemaLessUrlLowerCase = removeSchemaFromUrl(lowerCaseUrl);
374-
if (schemaLessUrlLowerCase == null) {
375-
continue;
376-
}
348+
continue;
377349
}
378350
if (schemaLessUrlLowerCase.startsWith(rule.search))
379351
return rule;
380352
381-
let ruleSearchHost = extractHostFromInvalidUrl(rule.search);
382-
if (ruleSearchHost != null) {
383-
384-
if (host == null) {
385-
continue;
386-
}
353+
rule.searchHost ??= extractHostFromInvalidUrl(rule.search);
354+
if (rule.searchHost != null) {
387355
388356
// should be the same
389-
if (ruleSearchHost != host && !host.endsWith('.' + ruleSearchHost))
357+
if (rule.searchHost != host && !host.endsWith('.' + rule.searchHost))
390358
continue;
391359
392360
// after this state, we are sure that the url is for the same domain, now just checking the path

0 commit comments

Comments
 (0)