forked from mirror/gorm
Grow SQL capacity to reduce allocation
This commit is contained in:
parent
aaf0725771
commit
9f19378304
|
@ -42,6 +42,7 @@ func Create(config *Config) func(db *gorm.DB) {
|
|||
}
|
||||
|
||||
if db.Statement.SQL.String() == "" {
|
||||
db.Statement.SQL.Grow(180)
|
||||
db.Statement.AddClauseIfNotExists(clause.Insert{
|
||||
Table: clause.Table{Name: db.Statement.Table},
|
||||
})
|
||||
|
@ -211,6 +212,7 @@ func ConvertToCreateValues(stmt *gorm.Statement) clause.Values {
|
|||
|
||||
switch stmt.ReflectValue.Kind() {
|
||||
case reflect.Slice, reflect.Array:
|
||||
stmt.SQL.Grow(stmt.ReflectValue.Len() * 15)
|
||||
values.Values = make([][]interface{}, stmt.ReflectValue.Len())
|
||||
defaultValueFieldsHavingValue := map[string][]interface{}{}
|
||||
for i := 0; i < stmt.ReflectValue.Len(); i++ {
|
||||
|
|
|
@ -30,6 +30,7 @@ func Delete(db *gorm.DB) {
|
|||
}
|
||||
|
||||
if db.Statement.SQL.String() == "" {
|
||||
db.Statement.SQL.Grow(100)
|
||||
db.Statement.AddClauseIfNotExists(clause.Delete{})
|
||||
|
||||
if db.Statement.Schema != nil {
|
||||
|
|
|
@ -37,6 +37,7 @@ func Query(db *gorm.DB) {
|
|||
}
|
||||
|
||||
func BuildQuerySQL(db *gorm.DB) {
|
||||
db.Statement.SQL.Grow(100)
|
||||
clauseSelect := clause.Select{Distinct: db.Statement.Distinct}
|
||||
|
||||
if db.Statement.ReflectValue.Kind() == reflect.Struct {
|
||||
|
|
|
@ -59,6 +59,7 @@ func Update(db *gorm.DB) {
|
|||
}
|
||||
|
||||
if db.Statement.SQL.String() == "" {
|
||||
db.Statement.SQL.Grow(180)
|
||||
db.Statement.AddClauseIfNotExists(clause.Update{})
|
||||
if set := ConvertToAssignments(db.Statement); len(set) != 0 {
|
||||
db.Statement.AddClause(set)
|
||||
|
|
Loading…
Reference in New Issue