vendor and go mod. add ldap file

This commit is contained in:
Xavier Henner
2019-07-09 09:53:46 +02:00
parent 29efc7be3f
commit 55ae63dc1d
61 changed files with 4696 additions and 2974 deletions

View File

@@ -3,38 +3,25 @@ package rcache
import (
"crypto/md5"
"regexp"
"runtime"
"sync"
)
var (
cores int
cache map[[16]byte]*regexp.Regexp = map[[16]byte]*regexp.Regexp{}
lock sync.RWMutex
)
func Get(expression string) *regexp.Regexp {
if cores == 0 {
cores = runtime.NumCPU()
}
key := md5.Sum([]byte(expression))
if cores > 1 {
lock.RLock()
}
lock.RLock()
if cache[key] != nil {
if cores > 1 {
defer lock.RUnlock()
}
defer lock.RUnlock()
return cache[key].Copy()
}
if cores > 1 {
lock.RUnlock()
}
lock.RUnlock()
if regex, err := regexp.Compile(expression); err == nil {
if cores > 1 {
lock.Lock()
defer lock.Unlock()
}
lock.Lock()
defer lock.Unlock()
cache[key] = regex
return cache[key].Copy()
}