mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/promrelabel: there is no need in calling regex.HasPrefix() after the optimization at 17289ff481
This commit is contained in:
parent
fa46c28c5f
commit
f38c9db74d
2 changed files with 6 additions and 14 deletions
|
@ -205,7 +205,8 @@ func (prc *parsedRelabelConfig) apply(labels []prompbmarshal.Label, labelsOffset
|
|||
return labels
|
||||
}
|
||||
}
|
||||
if re := prc.regex; re.HasPrefix() && !re.MatchString(bytesutil.ToUnsafeString(bb.B)) {
|
||||
sourceStr := bytesutil.ToUnsafeString(bb.B)
|
||||
if !prc.regex.MatchString(sourceStr) {
|
||||
// Fast path - regexp mismatch.
|
||||
relabelBufPool.Put(bb)
|
||||
return labels
|
||||
|
@ -216,7 +217,6 @@ func (prc *parsedRelabelConfig) apply(labels []prompbmarshal.Label, labelsOffset
|
|||
relabelBufPool.Put(bb)
|
||||
return labels
|
||||
}
|
||||
sourceStr := bytesutil.ToUnsafeString(bb.B)
|
||||
nameStr := prc.TargetLabel
|
||||
if prc.hasCaptureGroupInTargetLabel {
|
||||
nameStr = prc.expandCaptureGroups(nameStr, sourceStr, match)
|
||||
|
@ -401,6 +401,10 @@ func (prc *parsedRelabelConfig) replaceFullStringFast(s string) string {
|
|||
}
|
||||
}
|
||||
}
|
||||
if !prc.regex.MatchString(s) {
|
||||
// Fast path - regex mismatch
|
||||
return s
|
||||
}
|
||||
// Slow path - handle the rest of cases.
|
||||
return prc.stringReplacer.Transform(s)
|
||||
}
|
||||
|
@ -409,10 +413,6 @@ func (prc *parsedRelabelConfig) replaceFullStringFast(s string) string {
|
|||
//
|
||||
// s is returned as is if it doesn't match '^regex$'.
|
||||
func (prc *parsedRelabelConfig) replaceFullStringSlow(s string) string {
|
||||
if re := prc.regex; re.HasPrefix() && !re.MatchString(s) {
|
||||
// Fast path - regex mismatch
|
||||
return s
|
||||
}
|
||||
// Slow path - regexp processing
|
||||
match := prc.RegexAnchored.FindStringSubmatchIndex(s)
|
||||
if match == nil {
|
||||
|
|
|
@ -65,14 +65,6 @@ func NewPromRegex(expr string) (*PromRegex, error) {
|
|||
return pr, nil
|
||||
}
|
||||
|
||||
// HasPrefix returns true if pr contains non-empty literal prefix.
|
||||
//
|
||||
// For example, if pr is "foo(bar|baz)", then the prefix is "foo",
|
||||
// so HasPrefix() returns true.
|
||||
func (pr *PromRegex) HasPrefix() bool {
|
||||
return len(pr.prefix) > 0
|
||||
}
|
||||
|
||||
// MatchString retruns true if s matches pr.
|
||||
//
|
||||
// The pr is automatically anchored to the beginning and to the end
|
||||
|
|
Loading…
Reference in a new issue