Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
syncer: use strings.Builder for genKeyList; 453
Browse files Browse the repository at this point in the history
  • Loading branch information
csuzhangxc committed Apr 11, 2020
1 parent ff3eb9c commit 1be19f9
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions syncer/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,20 +441,21 @@ func findColumns(columns []*column, indexColumns map[string][]string) map[string
return result
}

func genKeyList(columns []*column, dataSeq []interface{}) string {
values := make([]string, 0, len(dataSeq))
func genKeyList(table string, columns []*column, dataSeq []interface{}) string {
var buf strings.Builder
buf.WriteString(table)
for i, data := range dataSeq {
values = append(values, columnValue(data, columns[i].unsigned, columns[i].tp))
// for key, I think no need to add the `,` separator.
buf.WriteString(columnValue(data, columns[i].unsigned, columns[i].tp))
}

return strings.Join(values, ",")
return buf.String()
}

func genMultipleKeys(value []interface{}, indexColumns map[string][]*column, table string) []string {
multipleKeys := make([]string, 0, len(indexColumns))
for _, indexCols := range indexColumns {
vals := getColumnData(indexCols, value)
multipleKeys = append(multipleKeys, table+genKeyList(indexCols, vals))
multipleKeys = append(multipleKeys, genKeyList(table, indexCols, vals))
}
return multipleKeys
}
Expand Down

0 comments on commit 1be19f9

Please sign in to comment.