Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libct/specconv: checkPropertyName speedup #3365

Merged
merged 2 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libcontainer/specconv/spec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
kolyshkin marked this conversation as resolved.
Show resolved Hide resolved
continue
}
Expand Down
4 changes: 2 additions & 2 deletions libcontainer/specconv/spec_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ func TestInitSystemdProps(t *testing.T) {
}
}

func TestIsValidName(t *testing.T) {
func TestCheckPropertyName(t *testing.T) {
testCases := []struct {
in string
valid bool
Expand All @@ -787,7 +787,7 @@ func TestIsValidName(t *testing.T) {
}
}

func BenchmarkIsValidName(b *testing.B) {
func BenchmarkCheckPropertyName(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, s := range []string{"", "xx", "xxx", "someValidName", "A name", "Кир", "მადლობა", "合い言葉"} {
_ = checkPropertyName(s)
Expand Down