-
-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove wrong loop in matchData #785
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,21 +130,19 @@ | |
|
||
func (mr MatchedRule) matchData(matchData types.MatchData) string { | ||
log := &strings.Builder{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's restructure this function to something like op := mr.Rule_.Operator()
if op == "" {
log.WriteString("Matched.")
return
}
// Rest of logic |
||
for _, matchData := range mr.MatchedDatas_ { | ||
v := matchData.Variable().Name() | ||
if matchData.Key() != "" { | ||
v += fmt.Sprintf(":%s", matchData.Key()) | ||
} | ||
value := matchData.Value() | ||
if len(value) > 200 { | ||
value = value[:200] | ||
} | ||
if mr.Rule_.Operator() != "" { | ||
log.WriteString(fmt.Sprintf("Matched \"Operator %s matched %s at %s.", | ||
"", value, v)) | ||
} else { | ||
log.WriteString("Matched.\"") | ||
} | ||
v := matchData.Variable().Name() | ||
if matchData.Key() != "" { | ||
v += fmt.Sprintf(":%s", matchData.Key()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to remove the intermediate strings, while it's more lines I guess it's still not so bad. We're basically expanding printf into code, which should be worth it for this very hot path function log.WriteString("Matched Operator ")
log.WriteString(op)
log.WriteString(" matched ")
log.WriteString(value)
log.WriteString(" at ")
log.WriteString(matchData.Variable().Name())
if matchData.Key() != "" {
log.WriteString(":")
log.WriteString(matchData.Key())
}
log.WriteString(".") |
||
} | ||
value := matchData.Value() | ||
Hayak3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if len(value) > 200 { | ||
value = value[:200] | ||
} | ||
if mr.Rule_.Operator() != "" { | ||
log.WriteString(fmt.Sprintf("Matched \"Operator %s matched %s at %s.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we need the first interpolation here @jptosso There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like a bug, let's fix it by interpolating the operator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW I'm wondering whether |
||
"", value, v)) | ||
} else { | ||
log.WriteString("Matched.\"") | ||
} | ||
return log.String() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's a bit unrelated, but while we're here, can we have this function accept
log *strings.Builder
and pass it in from the caller instead of creating a new one?