Skip to content

Commit

Permalink
Merge pull request #51 from cesco69/opt
Browse files Browse the repository at this point in the history
perf: avoid useless regex into route resolution
  • Loading branch information
dimdenGD authored Nov 11, 2024
2 parents edf17e1 + d815de8 commit 5d5e595
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const querystring = require("fast-querystring");
const etag = require("etag");
const { Stats } = require("fs");

const EMPTY_REGEX = new RegExp(``);

function fastQueryParse(query, options) {
const len = query.length;
if(len === 0){
Expand All @@ -46,7 +48,7 @@ function patternToRegex(pattern, isPrefix = false) {
return pattern;
}
if(isPrefix && pattern === '') {
return new RegExp(``);
return EMPTY_REGEX;
}

let regexPattern = pattern
Expand Down Expand Up @@ -207,7 +209,7 @@ function deprecated(oldMethod, newMethod, full = false) {
}

function findIndexStartingFrom(arr, fn, index = 0) {
for(let i = index; i < arr.length; i++) {
for(let i = index, end = arr.length; i < end; i++) {
if(fn(arr[i], i, arr)) {
return i;
}
Expand Down

0 comments on commit 5d5e595

Please sign in to comment.