File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
model-datastructure/src/commonMain/kotlin/org/modelix/model/persistent Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -26,11 +26,19 @@ object HashUtil {
26
26
}
27
27
28
28
fun isSha256 (value : String? ): Boolean {
29
- return if (value == null || value.length != 44 ) {
30
- false
31
- } else {
32
- value.matches(HASH_PATTERN )
29
+ // this implementation is equivalent to matching against HASH_PATTERN, but ~ 6 times faster
30
+ if (value == null ) return false
31
+ if (value.length != 44 ) return false
32
+ if (value[5 ] != ' *' ) return false
33
+ for (i in 0 .. 4 ) {
34
+ val c = value[i]
35
+ if (c !in ' a' .. ' z' && c !in ' A' .. ' Z' && c !in ' 0' .. ' 9' && c != ' -' && c != ' _' ) return false
33
36
}
37
+ for (i in 6 .. 43 ) {
38
+ val c = value[i]
39
+ if (c !in ' a' .. ' z' && c !in ' A' .. ' Z' && c !in ' 0' .. ' 9' && c != ' -' && c != ' _' ) return false
40
+ }
41
+ return true
34
42
}
35
43
36
44
fun extractSha256 (input : String? ): Iterable <String > {
You can’t perform that action at this time.
0 commit comments