Cache regex evaluation in i3.go

This commit is contained in:
eleksir
2026-03-31 00:23:48 +03:00
parent 6def26ef02
commit ad013fb8f5

View File

@@ -154,18 +154,16 @@ func HasWindows(className string, instanceName string) bool {
func FindWindowInstance(regexpStr string) bool {
var found = false
re, err := regexp.Compile(regexpStr)
if err != nil {
log.Printf("Unable to perform regexp match: %s", err)
return false
}
f := func(key any, value any) bool { //nolint: revive
keyStr := reflect.ValueOf(key).String()
re, err := regexp.Compile(regexpStr) // we do not want shit our pants and panic on
// erroneous regexp, we want log it to stderr, that it.
if err != nil {
log.Printf("Unable to perform regexp match: %s", err)
return true
}
if re.Match([]byte(keyStr)) { //nolint:mirror
found = true
@@ -185,18 +183,16 @@ func FindWindowInstance(regexpStr string) bool {
func FindWindowClass(regexpStr string) bool {
var found = false
re, err := regexp.Compile(regexpStr)
if err != nil {
log.Printf("Unable to perform regexp match: %s", err)
return false
}
f := func(key any, value any) bool { //nolint: revive
keyStr := reflect.ValueOf(key).String()
re, err := regexp.Compile(regexpStr) // we do not want shit our pants and panic on
// erroneous regexp, we want log it to stderr, that it.
if err != nil {
log.Printf("Unable to perform regexp match: %s", err)
return true
}
if re.Match([]byte(keyStr)) { //nolint:mirror
found = true