Skip to content

Commit 6360d15

Browse files
authored
perf(fslib): execute RegExp once when converting to/from PortablePath (#3392)
1 parent c839d23 commit 6360d15

File tree

5 files changed

+54
-12
lines changed

5 files changed

+54
-12
lines changed

.pnp.cjs

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.yarn/versions/c8661aba.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/core": patch
4+
"@yarnpkg/fslib": patch
5+
"@yarnpkg/plugin-pnp": patch
6+
"@yarnpkg/pnp": patch
7+
8+
declined:
9+
- "@yarnpkg/esbuild-plugin-pnp"
10+
- "@yarnpkg/plugin-compat"
11+
- "@yarnpkg/plugin-constraints"
12+
- "@yarnpkg/plugin-dlx"
13+
- "@yarnpkg/plugin-essentials"
14+
- "@yarnpkg/plugin-exec"
15+
- "@yarnpkg/plugin-file"
16+
- "@yarnpkg/plugin-git"
17+
- "@yarnpkg/plugin-github"
18+
- "@yarnpkg/plugin-http"
19+
- "@yarnpkg/plugin-init"
20+
- "@yarnpkg/plugin-interactive-tools"
21+
- "@yarnpkg/plugin-link"
22+
- "@yarnpkg/plugin-nm"
23+
- "@yarnpkg/plugin-npm"
24+
- "@yarnpkg/plugin-npm-cli"
25+
- "@yarnpkg/plugin-pack"
26+
- "@yarnpkg/plugin-patch"
27+
- "@yarnpkg/plugin-stage"
28+
- "@yarnpkg/plugin-typescript"
29+
- "@yarnpkg/plugin-version"
30+
- "@yarnpkg/plugin-workspace-tools"
31+
- vscode-zipfs
32+
- "@yarnpkg/builder"
33+
- "@yarnpkg/doctor"
34+
- "@yarnpkg/json-proxy"
35+
- "@yarnpkg/nm"
36+
- "@yarnpkg/pnpify"
37+
- "@yarnpkg/sdks"
38+
- "@yarnpkg/shell"

packages/yarnpkg-core/sources/worker-zip/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/yarnpkg-fslib/sources/path.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ function fromPortablePath(p: Path): NativePath {
124124
if (process.platform !== `win32`)
125125
return p as NativePath;
126126

127-
if (p.match(PORTABLE_PATH_REGEXP))
128-
p = p.replace(PORTABLE_PATH_REGEXP, `$1`);
129-
else if (p.match(UNC_PORTABLE_PATH_REGEXP))
130-
p = p.replace(UNC_PORTABLE_PATH_REGEXP, (match, p1, p2) => `\\\\${p1 ? `.\\` : ``}${p2}`);
127+
let portablePathMatch, uncPortablePathMatch;
128+
if ((portablePathMatch = p.match(PORTABLE_PATH_REGEXP)))
129+
p = portablePathMatch[1];
130+
else if ((uncPortablePathMatch = p.match(UNC_PORTABLE_PATH_REGEXP)))
131+
p = `\\\\${uncPortablePathMatch[1] ? `.\\` : ``}${uncPortablePathMatch[2]}`;
131132
else
132133
return p as NativePath;
133134

@@ -140,10 +141,11 @@ function toPortablePath(p: Path): PortablePath {
140141
if (process.platform !== `win32`)
141142
return p as PortablePath;
142143

143-
if (p.match(WINDOWS_PATH_REGEXP))
144-
p = p.replace(WINDOWS_PATH_REGEXP, `/$1`);
145-
else if (p.match(UNC_WINDOWS_PATH_REGEXP))
146-
p = p.replace(UNC_WINDOWS_PATH_REGEXP, (match, p1, p2) => `/unc/${p1 ? `.dot/` : ``}${p2}`);
144+
let windowsPathMatch, uncWindowsPathMatch;
145+
if ((windowsPathMatch = p.match(WINDOWS_PATH_REGEXP)))
146+
p = `/${windowsPathMatch[1]}`;
147+
else if ((uncWindowsPathMatch = p.match(UNC_WINDOWS_PATH_REGEXP)))
148+
p = `/unc/${uncWindowsPathMatch[1] ? `.dot/` : ``}${uncWindowsPathMatch[2]}`;
147149

148150
return p.replace(/\\/g, `/`) as PortablePath;
149151
}

packages/yarnpkg-pnp/sources/hook.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)