Compile regex on demand not in init
Should speed up app startup time a little since the compile happens for all users of the library. Compile only on use. [NO NEW TESTS NEEDED] Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
86a036c3d9
commit
b9ee165a91
|
@ -5,9 +5,9 @@ package resolvconf
|
|||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/storage/pkg/regexp"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -32,11 +32,11 @@ var (
|
|||
// ipLocalhost is a regex pattern for IPv4 or IPv6 loopback range.
|
||||
ipLocalhost = `((127\.([0-9]{1,3}\.){2}[0-9]{1,3})|(::1)$)`
|
||||
|
||||
localhostNSRegexp = regexp.MustCompile(`(?m)^nameserver\s+` + ipLocalhost + `\s*\n*`)
|
||||
nsIPv6Regexp = regexp.MustCompile(`(?m)^nameserver\s+` + ipv6Address + `\s*\n*`)
|
||||
nsRegexp = regexp.MustCompile(`^\s*nameserver\s*((` + ipv4Address + `)|(` + ipv6Address + `))\s*$`)
|
||||
searchRegexp = regexp.MustCompile(`^\s*search\s*(([^\s]+\s*)*)$`)
|
||||
optionsRegexp = regexp.MustCompile(`^\s*options\s*(([^\s]+\s*)*)$`)
|
||||
localhostNSRegexp = regexp.Delayed(`(?m)^nameserver\s+` + ipLocalhost + `\s*\n*`)
|
||||
nsIPv6Regexp = regexp.Delayed(`(?m)^nameserver\s+` + ipv6Address + `\s*\n*`)
|
||||
nsRegexp = regexp.Delayed(`^\s*nameserver\s*((` + ipv4Address + `)|(` + ipv6Address + `))\s*$`)
|
||||
searchRegexp = regexp.Delayed(`^\s*search\s*(([^\s]+\s*)*)$`)
|
||||
optionsRegexp = regexp.Delayed(`^\s*options\s*(([^\s]+\s*)*)$`)
|
||||
)
|
||||
|
||||
// filterResolvDNS cleans up the config in resolvConf. It has two main jobs:
|
||||
|
|
|
@ -5,12 +5,12 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/containers/common/pkg/configmaps/filedriver"
|
||||
"github.com/containers/storage/pkg/lockfile"
|
||||
"github.com/containers/storage/pkg/regexp"
|
||||
"github.com/containers/storage/pkg/stringid"
|
||||
)
|
||||
|
||||
|
@ -49,7 +49,7 @@ var configMapsFile = "configmaps.json"
|
|||
|
||||
// configMapNameRegexp matches valid configMap names
|
||||
// Allowed: 64 [a-zA-Z0-9-_.] characters, and the start and end character must be [a-zA-Z0-9]
|
||||
var configMapNameRegexp = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`)
|
||||
var configMapNameRegexp = regexp.Delayed(`^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`)
|
||||
|
||||
// ConfigMapManager holds information on handling configmaps
|
||||
type ConfigMapManager struct {
|
||||
|
|
|
@ -4,11 +4,11 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/containers/common/pkg/report/camelcase"
|
||||
"github.com/containers/storage/pkg/regexp"
|
||||
)
|
||||
|
||||
// Template embeds template.Template to add functionality to methods
|
||||
|
@ -160,7 +160,7 @@ func (t *Template) IsTable() bool {
|
|||
return t.isTable
|
||||
}
|
||||
|
||||
var rangeRegex = regexp.MustCompile(`(?s){{\s*range\s*\.\s*}}.*{{\s*end\s*-?\s*}}`)
|
||||
var rangeRegex = regexp.Delayed(`(?s){{\s*range\s*\.\s*}}.*{{\s*end\s*-?\s*}}`)
|
||||
|
||||
// EnforceRange ensures that the format string contains a range
|
||||
func EnforceRange(format string) string {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package report
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"github.com/containers/storage/pkg/regexp"
|
||||
)
|
||||
|
||||
// Check for json, {{json }} and {{ json. }} which are not valid go template,
|
||||
// {{json .}} is valid and thus not matched to let the template handle it like docker does.
|
||||
var jsonRegex = regexp.MustCompile(`^\s*(json|{{\s*json\.?\s*}})\s*$`)
|
||||
var jsonRegex = regexp.Delayed(`^\s*(json|{{\s*json\.?\s*}})\s*$`)
|
||||
|
||||
// JSONFormat test CLI --format string to be a JSON request
|
||||
//
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -13,6 +12,7 @@ import (
|
|||
"github.com/containers/common/pkg/secrets/passdriver"
|
||||
"github.com/containers/common/pkg/secrets/shelldriver"
|
||||
"github.com/containers/storage/pkg/lockfile"
|
||||
"github.com/containers/storage/pkg/regexp"
|
||||
"github.com/containers/storage/pkg/stringid"
|
||||
)
|
||||
|
||||
|
@ -51,7 +51,7 @@ var secretsFile = "secrets.json"
|
|||
|
||||
// secretNameRegexp matches valid secret names
|
||||
// Allowed: 64 [a-zA-Z0-9-_.] characters, and the start and end character must be [a-zA-Z0-9]
|
||||
var secretNameRegexp = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`)
|
||||
var secretNameRegexp = regexp.Delayed(`^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`)
|
||||
|
||||
// SecretsManager holds information on handling secrets
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue