Skip to content

Commit 5649db0

Browse files
committed
Perform regexp compile at package level
1 parent 5c54290 commit 5649db0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

arduino/cores/packagemanager/loader.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"regexp"
2323
"strconv"
2424
"strings"
25+
"sync"
2526

2627
"github.com/arduino/arduino-cli/arduino/cores"
2728
"github.com/arduino/arduino-cli/arduino/discovery"
@@ -420,6 +421,9 @@ func convertLegacyPlatformToPluggableDiscovery(platform *cores.PlatformRelease)
420421
}
421422
}
422423

424+
var netPropRegexp = regexp.MustCompile(`\{upload\.network\.([^}]+)\}`)
425+
var netPropRegexpMutex sync.Mutex
426+
423427
func convertLegacyNetworkPatternToPluggableDiscovery(props *properties.Map, newToolName string) *properties.Map {
424428
pattern, ok := props.GetOk("upload.network_pattern")
425429
if !ok {
@@ -434,11 +438,12 @@ func convertLegacyNetworkPatternToPluggableDiscovery(props *properties.Map, newT
434438
pattern = strings.ReplaceAll(pattern, "{network.password}", "{upload.field.password}")
435439
}
436440
// Search for "{upload.network.PROPERTY}"" and convert it to "{upload.port.property.PROPERTY}"
437-
netPropRegexp := regexp.MustCompile(`\{upload\.network\.([^}]+)\}`)
441+
netPropRegexpMutex.Lock()
438442
for netPropRegexp.MatchString(pattern) {
439443
netProp := netPropRegexp.FindStringSubmatch(pattern)[1]
440444
pattern = strings.ReplaceAll(pattern, "{upload.network."+netProp+"}", "{upload.port.properties."+netProp+"}")
441445
}
446+
netPropRegexpMutex.Unlock()
442447
props.Set("upload.pattern", pattern)
443448

444449
prefix := "tools." + newToolName + "."

0 commit comments

Comments
 (0)