mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-17 21:31:57 +01:00
Faster hex validation
This commit is contained in:
parent
d982f029e4
commit
5cd1c5ab90
@ -23,6 +23,7 @@ package com.vitorpamplona.quartz.benchmark
|
||||
import androidx.benchmark.junit4.BenchmarkRule
|
||||
import androidx.benchmark.junit4.measureRepeated
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.vitorpamplona.quartz.encoders.HexValidator
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
@ -65,4 +66,9 @@ class HexBenchmark {
|
||||
|
||||
benchmarkRule.measureRepeated { assertEquals(testHex, fr.acinq.secp256k1.Hex.encode(bytes)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isHex() {
|
||||
benchmarkRule.measureRepeated { HexValidator.isHex(testHex) }
|
||||
}
|
||||
}
|
||||
|
@ -34,29 +34,9 @@ fun HexKey.hexToByteArray(): ByteArray {
|
||||
object HexValidator {
|
||||
private fun isHexChar(c: Char): Boolean {
|
||||
return when (c) {
|
||||
'0',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
'7',
|
||||
'8',
|
||||
'9',
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
'd',
|
||||
'e',
|
||||
'f',
|
||||
'A',
|
||||
'B',
|
||||
'C',
|
||||
'D',
|
||||
'E',
|
||||
'F',
|
||||
-> true
|
||||
in '0'..'9' -> true
|
||||
in 'a'..'f' -> true
|
||||
in 'A'..'F' -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user