2828# is a substring of the path once the substitution `/src/` -> `/test/` is
2929# applied
3030
31+ $global :ruleCacheC = $null ;
32+ $global :ruleCacheCPP = $null ;
33+ $global :enableRuleCache = $false
3134function Get-RuleForPath {
3235 param ([Parameter (Mandatory )]
3336 [string ]
@@ -41,9 +44,30 @@ function Get-RuleForPath {
4144 $allQueries = @ ()
4245 $queriesToCheck = @ ()
4346
44- # load all the queries
45- foreach ($s in $AVAILABLE_SUITES ) {
46- $allQueries += Get-RulesInSuite - Suite $s - Language $Language
47+ if ($global :enableRuleCache ){
48+ # load all the queries
49+ if ($Language -eq ' cpp' ){
50+ $ruleCache = $global :ruleCacheCPP
51+ }else {
52+ $ruleCache = $global :ruleCacheC
53+ }
54+ }
55+
56+ if (-not $ruleCache ){
57+
58+ foreach ($s in $AVAILABLE_SUITES ) {
59+ $allQueries += Get-RulesInSuite - Suite $s - Language $Language
60+ }
61+
62+ if ($global :enableRuleCache ){
63+ if ($Language -eq ' cpp' ){
64+ $global :ruleCacheCPP = $allQueries
65+ }else {
66+ $global :ruleCacheC = $allQueries
67+ }
68+ }
69+ }else {
70+ $allQueries = $ruleCache
4771 }
4872
4973 $modifiedPathWithReplacement = Join-Path (Resolve-Path . - Relative) $Path
@@ -57,12 +81,11 @@ function Get-RuleForPath {
5781
5882 # for each query, create the test directory
5983 foreach ($q in $allQueries ){
60-
6184 # get test directory
6285 $testDirs = (Get-ATestDirectory - RuleObject $q - Language $Language )
6386 foreach ($testDirectory in $testDirs ){
6487 # resolve path to be compatible
65- $testPath = Join-Path (Resolve-Path . - Relative) $testDirectory
88+ $testPath = ( Join-Path (Resolve-Path . - Relative) $testDirectory ) + [ IO.Path ]::DirectorySeparatorChar
6689
6790 # see if the TEST directory is a substring of the full path
6891 if ($modifiedPath.StartsWith ($testPath )){
0 commit comments