| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 02fbff4 commit a2b9095
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -947,5 +947,6 @@ function matchGlobPattern(path, pattern, windows = isWindows) { | |||
| 947 | 947 | module.exports = { | |
| 948 | 948 | __proto__: null, | |
| 949 | 949 | Glob, | |
| 950 | + createMatcher, | ||
| 950 | 951 | matchGlobPattern, | |
| 951 | 952 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,7 +38,7 @@ const { | |||
| 38 | 38 | ERR_SOURCE_MAP_MISSING_SOURCE, | |
| 39 | 39 | }, | |
| 40 | 40 | } = require('internal/errors'); | |
| 41 | - const { matchGlobPattern } = require('internal/fs/glob'); | ||
| 41 | + const { createMatcher } = require('internal/fs/glob'); | ||
| 42 | 42 | const { constants: { kMockSearchParam } } = require('internal/test_runner/mock/loader'); | |
| 43 | 43 | ||
| 44 | 44 | const kCoverageFileRegex = /^coverage-(\d+)-(\d{13})-(\d+)\.json$/; | |
@@ -87,6 +87,8 @@ class TestCoverage { | |||
| 87 | 87 | #sourceLines = new SafeMap(); | |
| 88 | 88 | #typeScriptLines = new SafeSet(); | |
| 89 | 89 | #skipCache = new SafeMap(); | |
| 90 | + #excludeMatchers = null; | ||
| 91 | + #includeMatchers = null; | ||
| 90 | 92 | ||
| 91 | 93 | getLines(fileUrl, source) { | |
| 92 | 94 | // Split the file source into lines. Make sure the lines maintain their | |
@@ -551,28 +553,27 @@ class TestCoverage { | |||
| 551 | 553 | ||
| 552 | 554 | const absolutePath = fileURLToPath(url); | |
| 553 | 555 | const relativePath = relative(this.options.cwd, absolutePath); | |
| 554 | - const { | ||
| 555 | - coverageExcludeGlobs: excludeGlobs, | ||
| 556 | - coverageIncludeGlobs: includeGlobs, | ||
| 557 | - } = this.options; | ||
| 556 | + // The exclude/include globs are fixed for the lifetime of this | ||
| 557 | + // TestCoverage instance, so compile each glob to a matcher once and reuse | ||
| 558 | + // it for every file. Building a fresh Minimatch per call (the previous | ||
| 559 | + // behavior) dominated the coverage report time, scaling with | ||
| 560 | + // files * globs. | ||
| 561 | + this.#excludeMatchers ??= ArrayPrototypeMap( | ||
| 562 | + this.options.coverageExcludeGlobs ?? [], (pattern) => createMatcher(pattern)); | ||
| 563 | + this.#includeMatchers ??= ArrayPrototypeMap( | ||
| 564 | + this.options.coverageIncludeGlobs ?? [], (pattern) => createMatcher(pattern)); | ||
| 558 | 565 | ||
| 559 | 566 | // This check filters out files that match the exclude globs. | |
| 560 | - if (excludeGlobs?.length > 0) { | ||
| 561 | - for (let i = 0; i < excludeGlobs.length; ++i) { | ||
| 562 | - if ( | ||
| 563 | - matchGlobPattern(relativePath, excludeGlobs[i]) || | ||
| 564 | - matchGlobPattern(absolutePath, excludeGlobs[i]) | ||
| 565 | - ) return true; | ||
| 566 | - } | ||
| 567 | + for (let i = 0; i < this.#excludeMatchers.length; ++i) { | ||
| 568 | + const matcher = this.#excludeMatchers[i]; | ||
| 569 | + if (matcher.match(relativePath) || matcher.match(absolutePath)) return true; | ||
| 567 | 570 | } | |
| 568 | 571 | ||
| 569 | 572 | // This check filters out files that do not match the include globs. | |
| 570 | - if (includeGlobs?.length > 0) { | ||
| 571 | - for (let i = 0; i < includeGlobs.length; ++i) { | ||
| 572 | - if ( | ||
| 573 | - matchGlobPattern(relativePath, includeGlobs[i]) || | ||
| 574 | - matchGlobPattern(absolutePath, includeGlobs[i]) | ||
| 575 | - ) return false; | ||
| 573 | + if (this.#includeMatchers.length > 0) { | ||
| 574 | + for (let i = 0; i < this.#includeMatchers.length; ++i) { | ||
| 575 | + const matcher = this.#includeMatchers[i]; | ||
| 576 | + if (matcher.match(relativePath) || matcher.match(absolutePath)) return false; | ||
| 576 | 577 | } | |
| 577 | 578 | return true; | |
| 578 | 579 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments