Skip to content

Commit

Permalink
Another self review
Browse files Browse the repository at this point in the history
1. Use iota for op type

2. Optimize binary diff parsing when 0 bytes (don't allocate)

Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Dec 21, 2024
1 parent dcec5f6 commit 64e0422
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions go/mysql/binlog/binlog_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ https://github.com/noplay/python-mysql-replication/blob/175df28cc8b536a68522ff9b
type jsonDiffOp uint8

const (
jsonDiffOpReplace = jsonDiffOp(0)
jsonDiffOpInsert = jsonDiffOp(1)
jsonDiffOpRemove = jsonDiffOp(2)
jsonDiffOpReplace = jsonDiffOp(iota)
jsonDiffOpInsert
jsonDiffOpRemove
)

// ParseBinaryJSON provides the parsing function from the mysql binary json
Expand All @@ -75,6 +75,10 @@ func ParseBinaryJSON(data []byte) (*json.Value, error) {
// ParseBinaryJSONDiff provides the parsing function from the binary MySQL
// JSON diff representation to an SQL expression.
func ParseBinaryJSONDiff(data []byte) (sqltypes.Value, error) {
if len(data) == 0 {
return sqltypes.MakeTrusted(sqltypes.Expression, data), nil
}

diff := bytes.Buffer{}
// Reasonable estimate of the space we'll need to build the SQL
// expression in order to try and avoid reallocations w/o
Expand Down

0 comments on commit 64e0422

Please sign in to comment.