Skip to content

Commit

Permalink
regexp: remove mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
mcuadros committed May 5, 2020
1 parent dd35597 commit 3302cab
Showing 1 changed file with 0 additions and 37 deletions.
37 changes: 0 additions & 37 deletions regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,10 @@ type Regexp struct {

numCaptures int32
namedGroupInfo NamedGroupInfo
mutex *sync.Mutex
}

// NewRegexp creates and initializes a new Regexp with the given pattern and option.
func NewRegexp(pattern string, option int) (*Regexp, error) {
re, err := initRegexp(&Regexp{pattern: pattern, encoding: C.ONIG_ENCODING_UTF8}, option)
if err != nil {
return nil, err
}

re.mutex = new(sync.Mutex)
return re, nil
}

// NewRegexpNonThreadsafe creates and initializes a new Regexp with the given
// pattern and option. The resulting regexp is not thread-safe.
func NewRegexpNonThreadsafe(pattern string, option int) (*Regexp, error) {
return initRegexp(&Regexp{pattern: pattern, encoding: C.ONIG_ENCODING_UTF8}, option)
}

Expand Down Expand Up @@ -119,22 +106,7 @@ func MustCompileASCII(str string) *Regexp {
return regexp
}

func (re *Regexp) lock() {
if re.mutex != nil {
re.mutex.Lock()
}
}

func (re *Regexp) unlock() {
if re.mutex != nil {
re.mutex.Unlock()
}
}

func (re *Regexp) Free() {
re.lock()
defer re.unlock()

mutex.Lock()
if re.regex != nil {
C.onig_free(re.regex)
Expand Down Expand Up @@ -194,9 +166,6 @@ func (re *Regexp) getNamedGroupInfo() NamedGroupInfo {
}

func (re *Regexp) find(b []byte, n int, offset int) []int {
re.lock()
defer re.unlock()

match := make([]int, re.numCaptures*2)

if n == 0 {
Expand Down Expand Up @@ -504,9 +473,6 @@ func (re *Regexp) MatchString(s string) bool {
}

func (re *Regexp) NumSubexp() int {
re.lock()
defer re.unlock()

return (int)(C.onig_number_of_captures(re.regex))
}

Expand Down Expand Up @@ -614,9 +580,6 @@ func (re *Regexp) ReplaceAllStringFunc(src string, repl func(string) string) str
}

func (re *Regexp) String() string {
re.lock()
defer re.unlock()

return re.pattern
}

Expand Down

0 comments on commit 3302cab

Please sign in to comment.