Skip to content

Commit

Permalink
Do not preallocate regex in init program
Browse files Browse the repository at this point in the history
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 <dwalsh@redhat.com>
  • Loading branch information
rhatdan authored and lumjjb committed Jan 15, 2023
1 parent e2217b9 commit e0cec6f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion gpg.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"regexp"
"strconv"
"strings"
"sync"

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

var emailPattern = regexp.MustCompile(`uid\s+\[.*\]\s.*\s<(?P<email>.+)>`)
var (
onceRegexp sync.Once
emailPattern *regexp.Regexp
)

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

0 comments on commit e0cec6f

Please sign in to comment.