mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
libct/specconv: improve checkPropertyName
Commit029b73c1breplaced a regular expression with code checking the characters. Despite what the comment said about ASCII, the check was performed rune by rune, not byte by byte. Note the check was still correct, basically comparing int32's, but the byte by byte way is a tad faster and more straightforward. The change also fixes the issue of a misleading comment. Benchmark before/after shows a modest improvement: name old time/op new time/op delta CheckPropertyName-4 164ns ± 2% 123ns ± 2% -24.73% (p=0.029 n=4+4) name old alloc/op new alloc/op delta CheckPropertyName-4 96.0B ± 0% 64.0B ± 0% -33.33% (p=0.029 n=4+4) name old allocs/op new allocs/op delta CheckPropertyName-4 6.00 ± 0% 4.00 ± 0% -33.33% (p=0.029 n=4+4) Fixes:029b73c1bSigned-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -538,8 +538,10 @@ func checkPropertyName(s string) error {
|
||||
if len(s) < 3 {
|
||||
return errors.New("too short")
|
||||
}
|
||||
// Check ASCII characters rather than Unicode runes.
|
||||
for _, ch := range s {
|
||||
// Check ASCII characters rather than Unicode runes,
|
||||
// so we have to use indexes rather than range.
|
||||
for i := 0; i < len(s); i++ {
|
||||
ch := s[i]
|
||||
if (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user