Skip to content

Commit 4ec5b90

Browse files
author
Reinaldy Rafli
authored
Merge pull request #9 from aldy505/perf/builder
perf: migrate bytes.Buffer to strings.Builder for micro optimization
2 parents f1008bd + 3e4261d commit 4ec5b90

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

create.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package bob
22

33
import (
4-
"bytes"
54
"errors"
65
"strings"
76

@@ -205,7 +204,7 @@ func (d *createData) ToSql() (sqlStr string, args []interface{}, err error) {
205204
return
206205
}
207206

208-
sql := &bytes.Buffer{}
207+
var sql strings.Builder
209208

210209
sql.WriteString("CREATE TABLE ")
211210

has.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package bob
22

33
import (
4-
"bytes"
54
"errors"
5+
"strings"
66

77
"github.com/lann/builder"
88
)
@@ -50,7 +50,7 @@ func (h HasBuilder) ToSql() (string, []interface{}, error) {
5050

5151
// ToSql returns 3 variables filled out with the correct values based on bindings, etc.
5252
func (d *hasData) ToSql() (sqlStr string, args []interface{}, err error) {
53-
sql := &bytes.Buffer{}
53+
var sql strings.Builder
5454
if d.Name == "" {
5555
err = errors.New("has statement should have a table name")
5656
return

internal.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ func createArgs(keys ...interface{}) []interface{} {
1414
}
1515

1616
// isIn checks if an array have a value
17-
func isIn(arr []string, value string) bool {
18-
for _, item := range arr {
19-
if item == value {
20-
return true
21-
}
22-
}
23-
return false
24-
}
17+
// func isIn(arr []string, value string) bool {
18+
// for _, item := range arr {
19+
// if item == value {
20+
// return true
21+
// }
22+
// }
23+
// return false
24+
// }
2525

26-
// findPosition search for value position on an array
27-
func findPosition(arr []string, value string) int {
28-
for i, item := range arr {
29-
if item == value {
30-
return i
31-
}
32-
}
33-
return -1
34-
}
26+
// // findPosition search for value position on an array
27+
// func findPosition(arr []string, value string) int {
28+
// for i, item := range arr {
29+
// if item == value {
30+
// return i
31+
// }
32+
// }
33+
// return -1
34+
// }

upsert.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package bob
22

33
import (
4-
"bytes"
54
"errors"
65
"strings"
76

@@ -98,7 +97,7 @@ func (d *upsertData) ToSql() (sqlStr string, args []interface{}, err error) {
9897
return
9998
}
10099

101-
sql := &bytes.Buffer{}
100+
var sql strings.Builder
102101

103102
if d.Dialect == MSSQL {
104103
if len(d.Key) == 0 {

0 commit comments

Comments
 (0)