mirror of https://github.com/aldy505/bob.git
perf: migrate bytes.Buffer to strings.Builder for micro optimization
This commit is contained in:
parent
f1008bdf4a
commit
3e4261df9e
|
@ -1,7 +1,6 @@
|
||||||
package bob
|
package bob
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -205,7 +204,7 @@ func (d *createData) ToSql() (sqlStr string, args []interface{}, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sql := &bytes.Buffer{}
|
var sql strings.Builder
|
||||||
|
|
||||||
sql.WriteString("CREATE TABLE ")
|
sql.WriteString("CREATE TABLE ")
|
||||||
|
|
||||||
|
|
4
has.go
4
has.go
|
@ -1,8 +1,8 @@
|
||||||
package bob
|
package bob
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/lann/builder"
|
"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.
|
// ToSql returns 3 variables filled out with the correct values based on bindings, etc.
|
||||||
func (d *hasData) ToSql() (sqlStr string, args []interface{}, err error) {
|
func (d *hasData) ToSql() (sqlStr string, args []interface{}, err error) {
|
||||||
sql := &bytes.Buffer{}
|
var sql strings.Builder
|
||||||
if d.Name == "" {
|
if d.Name == "" {
|
||||||
err = errors.New("has statement should have a table name")
|
err = errors.New("has statement should have a table name")
|
||||||
return
|
return
|
||||||
|
|
34
internal.go
34
internal.go
|
@ -14,21 +14,21 @@ func createArgs(keys ...interface{}) []interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
// isIn checks if an array have a value
|
// isIn checks if an array have a value
|
||||||
func isIn(arr []string, value string) bool {
|
// func isIn(arr []string, value string) bool {
|
||||||
for _, item := range arr {
|
// for _, item := range arr {
|
||||||
if item == value {
|
// if item == value {
|
||||||
return true
|
// return true
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return false
|
// return false
|
||||||
}
|
// }
|
||||||
|
|
||||||
// findPosition search for value position on an array
|
// // findPosition search for value position on an array
|
||||||
func findPosition(arr []string, value string) int {
|
// func findPosition(arr []string, value string) int {
|
||||||
for i, item := range arr {
|
// for i, item := range arr {
|
||||||
if item == value {
|
// if item == value {
|
||||||
return i
|
// return i
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return -1
|
// return -1
|
||||||
}
|
// }
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package bob
|
package bob
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -98,7 +97,7 @@ func (d *upsertData) ToSql() (sqlStr string, args []interface{}, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sql := &bytes.Buffer{}
|
var sql strings.Builder
|
||||||
|
|
||||||
if d.Dialect == MSSQL {
|
if d.Dialect == MSSQL {
|
||||||
if len(d.Key) == 0 {
|
if len(d.Key) == 0 {
|
||||||
|
|
Loading…
Reference in New Issue