perf: avoid unnecessary byte/string conversion (#10012)
We can use alternative functions to avoid unnecessary byte/string conversion calls and reduce allocations. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
parent
19de8af350
commit
d02ba28b96
4 changed files with 8 additions and 8 deletions
|
@ -197,7 +197,7 @@ func dumpSecretAuthMap(filename string, secret *api.Secret) error {
|
||||||
for user, pass := range secret.Data {
|
for user, pass := range secret.Data {
|
||||||
builder.WriteString(user)
|
builder.WriteString(user)
|
||||||
builder.WriteString(":")
|
builder.WriteString(":")
|
||||||
builder.WriteString(string(pass))
|
builder.Write(pass)
|
||||||
builder.WriteString("\n")
|
builder.WriteString("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ func ValidMethod(method string) bool {
|
||||||
|
|
||||||
// ValidHeader checks is the provided string satisfies the header's name regex
|
// ValidHeader checks is the provided string satisfies the header's name regex
|
||||||
func ValidHeader(header string) bool {
|
func ValidHeader(header string) bool {
|
||||||
return headerRegexp.Match([]byte(header))
|
return headerRegexp.MatchString(header)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidCacheDuration checks if the provided string is a valid cache duration
|
// ValidCacheDuration checks if the provided string is a valid cache duration
|
||||||
|
@ -159,13 +159,13 @@ func ValidCacheDuration(duration string) bool {
|
||||||
if len(element) == 0 {
|
if len(element) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if statusCodeRegex.Match([]byte(element)) {
|
if statusCodeRegex.MatchString(element) {
|
||||||
if seenDuration {
|
if seenDuration {
|
||||||
return false // code after duration
|
return false // code after duration
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if durationRegex.Match([]byte(element)) {
|
if durationRegex.MatchString(element) {
|
||||||
seenDuration = true
|
seenDuration = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ func CreateSSLCert(cert, key []byte, uid string) (*ingress.SSLCert, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pemCertBuffer.Write([]byte("\n"))
|
pemCertBuffer.WriteString("\n")
|
||||||
pemCertBuffer.Write(key)
|
pemCertBuffer.Write(key)
|
||||||
|
|
||||||
pemBlock, _ := pem.Decode(pemCertBuffer.Bytes())
|
pemBlock, _ := pem.Decode(pemCertBuffer.Bytes())
|
||||||
|
@ -195,12 +195,12 @@ func StoreSSLCertOnDisk(name string, sslCert *ingress.SSLCert) (string, error) {
|
||||||
func ConfigureCACertWithCertAndKey(name string, ca []byte, sslCert *ingress.SSLCert) error {
|
func ConfigureCACertWithCertAndKey(name string, ca []byte, sslCert *ingress.SSLCert) error {
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
|
|
||||||
_, err := buffer.Write([]byte(sslCert.PemCertKey))
|
_, err := buffer.WriteString(sslCert.PemCertKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not append newline to cert file %v: %v", sslCert.CAFileName, err)
|
return fmt.Errorf("could not append newline to cert file %v: %v", sslCert.CAFileName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = buffer.Write([]byte("\n"))
|
_, err = buffer.WriteString("\n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not append newline to cert file %v: %v", sslCert.CAFileName, err)
|
return fmt.Errorf("could not append newline to cert file %v: %v", sslCert.CAFileName, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ var _ = framework.DescribeSetting("OCSP", func() {
|
||||||
|
|
||||||
var pemCertBuffer bytes.Buffer
|
var pemCertBuffer bytes.Buffer
|
||||||
pemCertBuffer.Write(leafCert)
|
pemCertBuffer.Write(leafCert)
|
||||||
pemCertBuffer.Write([]byte("\n"))
|
pemCertBuffer.WriteString("\n")
|
||||||
pemCertBuffer.Write(intermediateCa)
|
pemCertBuffer.Write(intermediateCa)
|
||||||
|
|
||||||
f.EnsureSecret(&corev1.Secret{
|
f.EnsureSecret(&corev1.Secret{
|
||||||
|
|
Loading…
Reference in a new issue