Merge pull request #9 from aldy505/perf/builder

perf: migrate bytes.Buffer to strings.Builder for micro optimization
This commit is contained in:
Reinaldy Rafli 2021-11-05 12:21:26 +07:00 committed by GitHub
commit 4ec5b9092b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 23 deletions

View File

@ -1,7 +1,6 @@
package bob
import (
"bytes"
"errors"
"strings"
@ -205,7 +204,7 @@ func (d *createData) ToSql() (sqlStr string, args []interface{}, err error) {
return
}
sql := &bytes.Buffer{}
var sql strings.Builder
sql.WriteString("CREATE TABLE ")

4
has.go
View File

@ -1,8 +1,8 @@
package bob
import (
"bytes"
"errors"
"strings"
"github.com/lann/builder"
)
@ -50,7 +50,7 @@ func (h HasBuilder) ToSql() (string, []interface{}, error) {
// ToSql returns 3 variables filled out with the correct values based on bindings, etc.
func (d *hasData) ToSql() (sqlStr string, args []interface{}, err error) {
sql := &bytes.Buffer{}
var sql strings.Builder
if d.Name == "" {
err = errors.New("has statement should have a table name")
return

View File

@ -14,21 +14,21 @@ func createArgs(keys ...interface{}) []interface{} {
}
// isIn checks if an array have a value
func isIn(arr []string, value string) bool {
for _, item := range arr {
if item == value {
return true
}
}
return false
}
// func isIn(arr []string, value string) bool {
// for _, item := range arr {
// if item == value {
// return true
// }
// }
// return false
// }
// findPosition search for value position on an array
func findPosition(arr []string, value string) int {
for i, item := range arr {
if item == value {
return i
}
}
return -1
}
// // findPosition search for value position on an array
// func findPosition(arr []string, value string) int {
// for i, item := range arr {
// if item == value {
// return i
// }
// }
// return -1
// }

View File

@ -1,7 +1,6 @@
package bob
import (
"bytes"
"errors"
"strings"
@ -98,7 +97,7 @@ func (d *upsertData) ToSql() (sqlStr string, args []interface{}, err error) {
return
}
sql := &bytes.Buffer{}
var sql strings.Builder
if d.Dialect == MSSQL {
if len(d.Key) == 0 {