Skip to content
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

proxy: improve performance of isStmt functions #10000

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions pkg/proxy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ var (
commit = "[cC][oO][mM][mM][iI][tT]"
rollback = "[rR][oO][lL][lL][bB][aA][cC][kK]"

beginPattern = fmt.Sprintf("^%s(%s)%s%s%s$",
spaceAtLeastZero, begin, spaceAtLeastZero, end, spaceAtLeastZero)
commitPattern = fmt.Sprintf("^%s(%s)%s%s%s$",
spaceAtLeastZero, commit, spaceAtLeastZero, end, spaceAtLeastZero)
rollbackPattern = fmt.Sprintf("^%s(%s)%s%s%s$",
spaceAtLeastZero, rollback, spaceAtLeastZero, end, spaceAtLeastZero)
beginRegex = regexp.MustCompile(fmt.Sprintf("^%s(%s)%s%s%s$",
spaceAtLeastZero, begin, spaceAtLeastZero, end, spaceAtLeastZero))
commitRegex = regexp.MustCompile(fmt.Sprintf("^%s(%s)%s%s%s$",
spaceAtLeastZero, commit, spaceAtLeastZero, end, spaceAtLeastZero))
rollbackRegex = regexp.MustCompile(fmt.Sprintf("^%s(%s)%s%s%s$",
spaceAtLeastZero, rollback, spaceAtLeastZero, end, spaceAtLeastZero))
)

// makeOKPacket returns an OK packet
Expand Down Expand Up @@ -130,20 +130,17 @@ func pickTunnels(tuns tunnelSet, n int) []*tunnel {

// isStmtBegin returns true iff it is begin statement.
func isStmtBegin(c []byte) bool {
matched, _ := regexp.MatchString(beginPattern, string(c))
return matched
return beginRegex.Match(c)
}

// isStmtCommit returns true iff it is commit statement.
func isStmtCommit(c []byte) bool {
matched, _ := regexp.MatchString(commitPattern, string(c))
return matched
return commitRegex.Match(c)
}

// isStmtRollback returns true iff it is rollback statement.
func isStmtRollback(c []byte) bool {
matched, _ := regexp.MatchString(rollbackPattern, string(c))
return matched
return rollbackRegex.Match(c)
}

// sortMap sorts a complex map instance.
Expand Down