Skip to content

Commit

Permalink
💄 compile regex one time
Browse files Browse the repository at this point in the history
  • Loading branch information
mfreeman451 committed May 22, 2024
1 parent 2e6f9e5 commit dda1e93
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ var (
updateInterval = 1000
)

var dataRegex = regexp.MustCompile(`(?m)^\s*(\S.*?)\s+(\d+)\s+(\d+\.\d+)\s+\d+\.\d+\s+`)

func setupUI() {
appleSiliconModel := getSOCInfo()
modelText = w.NewParagraph()
Expand Down Expand Up @@ -525,7 +527,6 @@ func updateProcessUI(processMetrics []ProcessMetrics) {

func parseProcessMetrics(powermetricsOutput string, processMetrics []ProcessMetrics) []ProcessMetrics {
lines := strings.Split(powermetricsOutput, "\n")
dataRegex := regexp.MustCompile(`(?m)^\s*(\S.*?)\s+(\d+)\s+(\d+\.\d+)\s+\d+\.\d+\s+`)
seen := make(map[int]bool) // Map to track seen process IDs
for _, line := range lines {
matches := dataRegex.FindStringSubmatch(line)
Expand Down

0 comments on commit dda1e93

Please sign in to comment.