Skip to content

Commit c473177

Browse files
committed
Make style cache thread safe
1 parent ffb3b07 commit c473177

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tools/utils/style/wrapper.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"strconv"
88
"strings"
9+
"sync"
910

1011
"kitty/tools/utils/shlex"
1112
)
@@ -318,13 +319,9 @@ func parse_spec(spec string) []escape_code {
318319
sgr := sgr_code{}
319320
sparts, _ := shlex.Split(spec)
320321
for _, p := range sparts {
321-
parts := strings.SplitN(p, "=", 2)
322-
key := parts[0]
323-
val := ""
324-
if len(parts) == 1 {
322+
key, val, found := strings.Cut(p, "=")
323+
if !found {
325324
val = "true"
326-
} else {
327-
val = parts[1]
328325
}
329326
switch key {
330327
case "fg":
@@ -355,8 +352,11 @@ func parse_spec(spec string) []escape_code {
355352
}
356353

357354
var parsed_spec_cache = make(map[string][]escape_code)
355+
var parsed_spec_cache_mutex = sync.Mutex{}
358356

359357
func cached_parse_spec(spec string) []escape_code {
358+
parsed_spec_cache_mutex.Lock()
359+
defer parsed_spec_cache_mutex.Unlock()
360360
if val, ok := parsed_spec_cache[spec]; ok {
361361
return val
362362
}

0 commit comments

Comments
 (0)