Skip to content

Commit 54fc0b3

Browse files
committed
perf: re-use double slash regex
Re-uses the regex and uses a global replace instead of a loop. Also removes the left-over `esm/` directory now that we're esm-only.
1 parent 7d9c1ed commit 54fc0b3

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

esm/package.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const ONE_DOT = '.';
7676
const TWO_DOTS = '..';
7777
const STRING_TYPE = 'string';
7878
const BACK_SLASH_RE = /\\/g;
79-
const DOUBLE_SLASH_RE = /\/\//;
79+
const DOUBLE_SLASH_RE = /\/\//g;
8080
const DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
8181
const REPLACER_RE = /^\.[/\\]/;
8282

@@ -113,8 +113,7 @@ function normalizePath(path: Path): Path {
113113
path = path.replace(/\\/g, '/');
114114
let prepend = false;
115115
if (path.startsWith('//')) prepend = true;
116-
const DOUBLE_SLASH_RE = /\/\//;
117-
while (path.match(DOUBLE_SLASH_RE)) path = path.replace(DOUBLE_SLASH_RE, '/');
116+
path = path.replace(DOUBLE_SLASH_RE, '/');
118117
if (prepend) path = '/' + path;
119118
return path;
120119
}
@@ -168,9 +167,7 @@ const toUnix = (string: string) => {
168167
if (str.startsWith(SLASH_SLASH)) {
169168
prepend = true;
170169
}
171-
while (str.match(DOUBLE_SLASH_RE)) {
172-
str = str.replace(DOUBLE_SLASH_RE, SLASH);
173-
}
170+
str = str.replace(DOUBLE_SLASH_RE, SLASH);
174171
if (prepend) {
175172
str = SLASH + str;
176173
}

0 commit comments

Comments
 (0)