mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-12 22:14:03 -08:00
refactor: split concurrent map from cache implementation
This commit is contained in:
parent
4bcef332a5
commit
8d35689170
|
@ -80,24 +80,15 @@ type environmentInfo interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type commandCache struct {
|
type commandCache struct {
|
||||||
commands map[string]string
|
commands *concurrentMap
|
||||||
lock sync.RWMutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *commandCache) set(command, path string) {
|
func (c *commandCache) set(command, path string) {
|
||||||
c.lock.Lock()
|
c.commands.set(command, path)
|
||||||
defer c.lock.Unlock()
|
|
||||||
c.commands[command] = path
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *commandCache) get(command string) (string, bool) {
|
func (c *commandCache) get(command string) (string, bool) {
|
||||||
c.lock.RLock()
|
return c.commands.get(command)
|
||||||
defer c.lock.RUnlock()
|
|
||||||
if cmd, ok := c.commands[command]; ok {
|
|
||||||
command = cmd
|
|
||||||
return command, true
|
|
||||||
}
|
|
||||||
return "", false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type tracer struct {
|
type tracer struct {
|
||||||
|
@ -145,11 +136,9 @@ type environment struct {
|
||||||
|
|
||||||
func (env *environment) init(args *args) {
|
func (env *environment) init(args *args) {
|
||||||
env.args = args
|
env.args = args
|
||||||
cmdCache := &commandCache{
|
env.cmdCache = &commandCache{
|
||||||
commands: make(map[string]string),
|
commands: newConcurrentMap(),
|
||||||
lock: sync.RWMutex{},
|
|
||||||
}
|
}
|
||||||
env.cmdCache = cmdCache
|
|
||||||
tracer := &tracer{
|
tracer := &tracer{
|
||||||
debug: *args.Debug,
|
debug: *args.Debug,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue