Skip to content

Commit 9fd9d87

Browse files
oshaiholgerbrandl
authored andcommitted
Avoid recompilation of annotation regexes (#152)
to avoid creating regex on each line
1 parent 1d41f28 commit 9fd9d87

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/main/kotlin/kscript/app/Script.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ data class Script(val lines: List<String>, val extension: String = "kts") : Iter
7171
}
7272

7373

74-
private fun isKscriptAnnotation(line: String) =
75-
listOf("DependsOn", "KotlinOpts", "Include", "EntryPoint", "MavenRepository", "DependsOnMaven")
76-
.any { line.contains("^@file:${it}[(]".toRegex()) }
74+
private val KSCRIPT_DIRECTIVE_ANNO: List<Regex> = listOf("DependsOn", "KotlinOpts", "Include", "EntryPoint", "MavenRepository", "DependsOnMaven")
75+
.map { "^@file:$it[(]".toRegex() }
7776

77+
private fun isKscriptAnnotation(line: String) =
78+
KSCRIPT_DIRECTIVE_ANNO.any { line.contains(it) }
7879

7980
//
8081
// Entry directive

0 commit comments

Comments
 (0)