Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
dropwhile committed Aug 27, 2023
1 parent 2ad2838 commit 76015a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
21 changes: 6 additions & 15 deletions pkg/htrie/glob_path_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
)

const globChar uint8 = 1
const globChar byte = 1

type BitMask uint8

Expand Down Expand Up @@ -48,7 +48,7 @@ func (m BitMask) String() string {

// A globPathNode represents a path checker that supports globbing comparisons
type globPathNode struct {
nodeChars []uint8
nodeChars []byte
nodeAttrs []BitMask
nodeTree [][]int
icase bool
Expand Down Expand Up @@ -133,28 +133,19 @@ func (gpn *globPathNode) globConsume(s string, index, mlen, nodeIndex int) bool
// otherwise we have some work to do...
// don't need to iter runes since we have ascii
for i := index; i < mlen; i++ {
part := uint8(s[i])
part := s[i]

// if icase, use lowercase letters for comparisons
// 'A' == 65; 'Z' == 90
if gpn.icase && 65 <= part && part <= 90 {
part = part + 32
}

x := gpn.nodeChars[curnode]
if x == globChar {
x = '*'
}
nextX := gpn.nodeChars[gpn.nodeTree[curnode][0]]
if nextX == globChar {
nextX = '*'
}

// optimize common single char after * globbing
// eg. .../*/...
// if we know the glob has one one subcandidate (next char), we consume until
// we hit one of those
if gpn.nodeAttrs[curnode]&oneShot != 0 && len(gpn.nodeTree[curnode]) > 0 {
if gpn.nodeAttrs[curnode]&oneShot != 0 {
idx := gpn.nodeTree[curnode][0]
if part != gpn.nodeChars[idx] {
continue
Expand Down Expand Up @@ -191,7 +182,7 @@ func (gpn *globPathNode) checkPath(s string, index, mlen int, nodeIndex int) boo
curnode := nodeIndex
// don't need to iter runes since we have ascii
for i := index; i < mlen; i++ {
part := uint8(s[i])
part := s[i]

// if icase, use lowercase letters for comparisons
// 'A' == 65; 'Z' == 90
Expand Down Expand Up @@ -284,7 +275,7 @@ func newGlobPathNode(icase bool) *globPathNode {
// and since we only /really/ care about lookup costs, just start with 0 initial
// map size and let it grow as needed
return &globPathNode{
nodeChars: []uint8{0},
nodeChars: []byte{0},
nodeTree: [][]int{{}},
nodeAttrs: []BitMask{0},
icase: icase,
Expand Down
4 changes: 4 additions & 0 deletions pkg/htrie/htrie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func BenchmarkHTrieCreate(b *testing.B) {
urls := []string{
"||*.example.com||*/test.png",
"|s|example.org|i|*/test.png",
"||foo.example.net||/test.png",
"||bar.example.net||/test.png",
"||*.bar.example.net||/test.png",
"||*.hodor.example.net||/*/test.png",
}
var err error
b.ResetTimer()
Expand Down

0 comments on commit 76015a0

Please sign in to comment.