Skip to content
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
4 changes: 2 additions & 2 deletions cmd/globtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ func main() {

if *benchCompile {
b := testing.Benchmark(func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
glob.Compile(*pattern, separators...)
}
})
fmt.Fprintf(w, "compile:\t%s\n", benchString(b))
}
if *benchMatch {
b := testing.Benchmark(func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
g.Match(*fixture)
}
})
Expand Down
2 changes: 1 addition & 1 deletion glob.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func QuoteMeta(s string) string {
b := make([]byte, 2*len(s))
j := 0
// A byte loop is correct here because all meta characters are ASCII.
for i := 0; i < len(s); i++ {
for i := range len(s) {
if syntax.IsSpecial(s[i]) {
b[j] = '\\'
j++
Expand Down
26 changes: 9 additions & 17 deletions glob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package glob
import (
"errors"
"fmt"
"maps"
"path/filepath"
"regexp"
"slices"
Expand Down Expand Up @@ -879,15 +880,15 @@ func BenchmarkPattern(b *testing.B) {
},
} {
b.Run(test.name+"-compile", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
MustCompile(test.pat)
}
})
pat := MustCompile(test.pat)
for _, key := range keysInOrder(test.input) {
for _, key := range slices.Sorted(maps.Keys(test.input)) {
str := test.input[key]
b.Run(test.name+"-match-"+key, func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
pat.Match(str)
}
})
Expand Down Expand Up @@ -1007,28 +1008,28 @@ func BenchmarkCompareGlobAndRegexp(b *testing.B) {
},
} {
b.Run(test.name+"-glob-compile", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
MustCompile(test.glob)
}
})
b.Run(test.name+"-regexp-compile", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
regexp.MustCompile(test.regexp)
}
})
var (
pat = MustCompile(test.glob)
exp = regexp.MustCompile(test.regexp)
)
for _, key := range keysInOrder(test.input) {
for _, key := range slices.Sorted(maps.Keys(test.input)) {
str := test.input[key]
b.Run(test.name+"-glob-"+key, func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
pat.Match(str)
}
})
b.Run(test.name+"-regexp-"+key, func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
exp.MatchString(str)
}
})
Expand Down Expand Up @@ -1127,12 +1128,3 @@ func TestPatternSeparatorsAliasing(t *testing.T) {
t.Errorf("Match() picked up the modification of the given slice")
}
}

func keysInOrder(m map[string]string) []string {
keys := make([]string, 0, len(m))
for key := range m {
keys = append(keys, key)
}
slices.Sort(keys)
return keys
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/gobwas/glob

go 1.22.0
go 1.24.0
2 changes: 1 addition & 1 deletion syntax/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ reading:
escaped = true
continue
}
if slices.Index(breakers, r) != -1 {
if slices.Contains(breakers, r) {
l.unread()
break reading
}
Expand Down