Files
node/test/parallel/test-path-glob-sections.js
T
Roberto Bianchi bb3f9176ca fs: reduce glob section allocations
Store prefix counts in section records to avoid a separate vector
and its allocations during multi-globstar matching.

Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>
PR-URL: https://github.com/nodejs/node/pull/66716
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-10-19 14:53:43 +00:00

26 lines
1.2 KiB
JavaScript

'use strict';
require('../common');
const assert = require('node:assert');
const { posix, win32 } = require('node:path');
for (const implementation of [posix, win32]) {
for (const count of [1, 2, 4, 8, 9, 10, 16]) {
for (const prefix of ['part', '\u00e9tage', '\u4e2d']) {
const names = Array.from({ length: count - 1 }, (_, index) => `${prefix}${index}`);
const pattern = ['**', ...names.flatMap((name) => [name, '**']), 'file.js'].join('/');
const parts = ['root', ...names.flatMap((name) => [name, 'dir']), 'file.js'];
assert.strictEqual(implementation.matchesGlob(parts.join(implementation.sep), pattern), true);
if (names.length) {
parts[parts.length - 3] = 'absent';
} else {
parts[parts.length - 1] = 'file.txt';
}
assert.strictEqual(implementation.matchesGlob(parts.join(implementation.sep), pattern), false);
}
}
assert.strictEqual(implementation.matchesGlob('root/.hidden/src/lib/file.js', '**/src/**/file.js'), false);
assert.strictEqual(implementation.matchesGlob('root/src/./lib/file.js', '**/src/**/file.js'), true);
assert.strictEqual(implementation.matchesGlob('root/src/lib/file.js/', '**/src/**/file.js'), true);
}