Rules-based browser launcher for TUI + GNOME. switchyard.aly.codes
tui gome bowser go
0

Configure Feed

Select the types of activity you want to include in your feed.

add regex cache

Aly Raffauf (Jan 24, 2026, 12:14 AM EST) 3bba86b9 0995efb1

+19 -7
+19 -7
src/pattern.go
··· 7 7 "strings" 8 8 ) 9 9 10 + var regexCache = make(map[string]*regexp.Regexp) 11 + 12 + func getCompiledRegex(pattern string) (*regexp.Regexp, bool) { 13 + if re, ok := regexCache[pattern]; ok { 14 + return re, true 15 + } 16 + re, err := regexp.Compile(pattern) 17 + if err != nil { 18 + return nil, false 19 + } 20 + regexCache[pattern] = re 21 + return re, true 22 + } 23 + 10 24 func matchesPattern(url, pattern, patternType string) bool { 11 25 switch patternType { 12 26 case "domain": ··· 15 29 case "keyword": 16 30 return strings.Contains(strings.ToLower(url), strings.ToLower(pattern)) 17 31 case "regex": 18 - re, err := regexp.Compile(pattern) 19 - if err != nil { 32 + re, ok := getCompiledRegex(pattern) 33 + if !ok { 20 34 return false 21 35 } 22 36 return re.MatchString(url) ··· 32 46 domain := extractDomain(url) 33 47 34 48 // Convert glob to regex: escape dots, convert * to .* 35 - pattern = strings.ReplaceAll(pattern, ".", "\\.") 36 - pattern = strings.ReplaceAll(pattern, "*", ".*") 37 - pattern = "^" + pattern + "$" 49 + regexPattern := "^" + strings.ReplaceAll(strings.ReplaceAll(pattern, ".", "\\."), "*", ".*") + "$" 38 50 39 - re, err := regexp.Compile(pattern) 40 - if err != nil { 51 + re, ok := getCompiledRegex(regexPattern) 52 + if !ok { 41 53 return false 42 54 } 43 55