Skip to content

Commit f461763

Browse files
authored
Merge pull request #19186 from github/tausbn/actions-fix-gettargetpath-performance
Actions: Fix bad performance in `getTargetPath`
2 parents e6cf737 + 8afdf25 commit f461763

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

shared/yaml/codeql/yaml/Yaml.qll

+18-8
Original file line numberDiff line numberDiff line change
@@ -424,14 +424,24 @@ module Make<InputSig Input> {
424424
* Gets the absolute path of the file included by this directive.
425425
*/
426426
private string getTargetPath() {
427-
exists(string path | path = this.getValue() |
428-
if path.matches("/%")
429-
then result = path
430-
else
431-
result =
432-
this.getDocument().getLocation().getFile().getParentContainer().getAbsolutePath() + "/" +
433-
path
434-
)
427+
result = this.getAbsolutePath()
428+
or
429+
result =
430+
this.getDocument().getLocation().getFile().getParentContainer().getAbsolutePath() + "/" +
431+
this.getRelativePath()
432+
}
433+
434+
/** Join-order helper for `getTargetPath`. Gets the path but only if it is an absolute path. */
435+
private string getAbsolutePath() {
436+
result = this.getValue() and
437+
result.matches("/%")
438+
}
439+
440+
/** Join-order helper for `getTargetPath`. Gets the path, but only if it is a relative path. */
441+
pragma[noinline]
442+
private string getRelativePath() {
443+
result = this.getValue() and
444+
not result.matches("/%")
435445
}
436446
}
437447

0 commit comments

Comments
 (0)