Skip to content

Commit e0cec6f

Browse files
rhatdanlumjjb
authored andcommitted
Do not preallocate regex in init program
We are trying to speed up the startup of container applications by not MustCompiling in init but waiting until first use of application. While this will only speed up start by a couple of microseconds, the more we get rid of the faster the apps will start. Signed-off-by: Daniel J Walsh <[email protected]>
1 parent e2217b9 commit e0cec6f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

gpg.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"regexp"
2525
"strconv"
2626
"strings"
27+
"sync"
2728

2829
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2930
"github.com/pkg/errors"
@@ -310,9 +311,15 @@ func resolveRecipients(gc GPGClient, recipients []string) []string {
310311
return result
311312
}
312313

313-
var emailPattern = regexp.MustCompile(`uid\s+\[.*\]\s.*\s<(?P<email>.+)>`)
314+
var (
315+
onceRegexp sync.Once
316+
emailPattern *regexp.Regexp
317+
)
314318

315319
func extractEmailFromDetails(details []byte) string {
320+
onceRegexp.Do(func() {
321+
emailPattern = regexp.MustCompile(`uid\s+\[.*\]\s.*\s<(?P<email>.+)>`)
322+
})
316323
loc := emailPattern.FindSubmatchIndex(details)
317324
if len(loc) == 0 {
318325
return ""

0 commit comments

Comments
 (0)