Skip to content

Commit dc7d072

Browse files
committed
perf(materialize): use slice for prefix removal
1 parent b43d2aa commit dc7d072

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

docs.config.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
"minLength": 1
5757
}
5858
},
59+
"unwrapSingleRootDir": {
60+
"type": "boolean"
61+
},
5962
"toc": {
6063
"anyOf": [
6164
{

src/materialize.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const resolveUnwrapPrefix = (
9797
let rootDir: string | null = null;
9898
for (const entry of entries) {
9999
const remaining = prefix
100-
? entry.normalized.replace(prefix, "")
100+
? entry.normalized.slice(prefix.length)
101101
: entry.normalized;
102102
const parts = remaining.split("/");
103103
if (parts.length < 2) {
@@ -206,7 +206,7 @@ export const materializeSource = async (params: MaterializeParams) => {
206206
const targetDirs = new Set<string>();
207207
for (const { normalized } of entries) {
208208
const rootPath = unwrapPrefix
209-
? normalized.replace(unwrapPrefix, "")
209+
? normalized.slice(unwrapPrefix.length)
210210
: normalized;
211211
targetDirs.add(path.posix.dirname(rootPath));
212212
}
@@ -265,8 +265,8 @@ export const materializeSource = async (params: MaterializeParams) => {
265265
return null;
266266
}
267267
const normalizedPath = unwrapPrefix
268-
? entry.normalized.replace(unwrapPrefix, "")
269-
: entry.relativePath;
268+
? entry.normalized.slice(unwrapPrefix.length)
269+
: entry.normalized;
270270
const targetPath = path.join(tempDir, normalizedPath);
271271
ensureSafePath(tempDir, targetPath);
272272
if (stats.size >= STREAM_COPY_THRESHOLD_BYTES) {
@@ -282,7 +282,7 @@ export const materializeSource = async (params: MaterializeParams) => {
282282
}
283283
return {
284284
path: unwrapPrefix
285-
? entry.normalized.replace(unwrapPrefix, "")
285+
? entry.normalized.slice(unwrapPrefix.length)
286286
: entry.normalized,
287287
size: stats.size,
288288
};

0 commit comments

Comments
 (0)