mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
Merge pull request #3365 from kolyshkin/checkPropertyName-speedup
libct/specconv: checkPropertyName speedup
This commit is contained in:
@@ -538,8 +538,10 @@ func checkPropertyName(s string) error {
|
|||||||
if len(s) < 3 {
|
if len(s) < 3 {
|
||||||
return errors.New("too short")
|
return errors.New("too short")
|
||||||
}
|
}
|
||||||
// Check ASCII characters rather than Unicode runes.
|
// Check ASCII characters rather than Unicode runes,
|
||||||
for _, ch := range s {
|
// 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') {
|
if (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -759,7 +759,7 @@ func TestInitSystemdProps(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsValidName(t *testing.T) {
|
func TestCheckPropertyName(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
in string
|
in string
|
||||||
valid bool
|
valid bool
|
||||||
@@ -784,7 +784,7 @@ func TestIsValidName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkIsValidName(b *testing.B) {
|
func BenchmarkCheckPropertyName(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
for _, s := range []string{"", "xx", "xxx", "someValidName", "A name", "Кир", "მადლობა", "合い言葉"} {
|
for _, s := range []string{"", "xx", "xxx", "someValidName", "A name", "Кир", "მადლობა", "合い言葉"} {
|
||||||
_ = checkPropertyName(s)
|
_ = checkPropertyName(s)
|
||||||
|
|||||||
Reference in New Issue
Block a user