Skip to content

Commit

Permalink
Tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
fasaxc committed Dec 6, 2024
1 parent e570829 commit 64ad3f7
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions libcalico-go/lib/selector/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ import (

const parserDebug = false

var (
sharedParserLock sync.Mutex
sharedParser = NewParser()
)

// Parse parses a string representation of a selector expression into a Selector.
func Parse(selector string) (sel Selector, err error) {
sharedParserLock.Lock()
Expand All @@ -34,18 +39,18 @@ func Parse(selector string) (sel Selector, err error) {
return sharedParser.Parse(selector)
}

var (
sharedValidatorLock sync.Mutex
sharedValidator = NewParser()
)

func Validate(selector string) (err error) {
sharedParserLock.Lock()
defer sharedParserLock.Unlock()
sharedValidatorLock.Lock()
defer sharedValidatorLock.Unlock()

return sharedParser.Validate(selector)
return sharedValidator.Validate(selector)
}

var (
sharedParserLock sync.Mutex
sharedParser = NewParser()
)

func NewParser() *Parser {
return &Parser{
tokBuf: make([]tokenizer.Token, 0, 128),
Expand Down

0 comments on commit 64ad3f7

Please sign in to comment.