-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
change the method of initializing slice #4097
change the method of initializing slice #4097
Conversation
Oops, the run all tests in the local tests directory went through. testing sqlite...
ok gorm.io/gorm 0.845s
? gorm.io/gorm/callbacks [no test files]
ok gorm.io/gorm/clause 2.513s
ok gorm.io/gorm/logger 0.851s
? gorm.io/gorm/migrator [no test files]
ok gorm.io/gorm/schema 1.325s
ok gorm.io/gorm/utils 0.909s
? gorm.io/gorm/utils/tests [no test files]
go: finding module for package gorm.io/driver/postgres
go: finding module for package gorm.io/driver/mysql
go: finding module for package gorm.io/driver/sqlite
go: finding module for package gorm.io/driver/sqlserver
go: found gorm.io/driver/mysql in gorm.io/driver/mysql v1.0.4
go: found gorm.io/driver/postgres in gorm.io/driver/postgres v1.0.8
go: found gorm.io/driver/sqlite in gorm.io/driver/sqlite v1.1.4
go: found gorm.io/driver/sqlserver in gorm.io/driver/sqlserver v1.0.6
ok gorm.io/gorm/tests 8.099s
testing mysql...
ok gorm.io/gorm 0.339s
? gorm.io/gorm/callbacks [no test files]
ok gorm.io/gorm/clause 1.449s
ok gorm.io/gorm/logger 0.135s
? gorm.io/gorm/migrator [no test files]
ok gorm.io/gorm/schema 0.559s
ok gorm.io/gorm/utils 0.214s
? gorm.io/gorm/utils/tests [no test files]
ok gorm.io/gorm/tests 44.006s
testing postgres...
ok gorm.io/gorm 0.172s
? gorm.io/gorm/callbacks [no test files]
ok gorm.io/gorm/clause 1.218s
ok gorm.io/gorm/logger 0.181s
? gorm.io/gorm/migrator [no test files]
ok gorm.io/gorm/schema 0.554s
ok gorm.io/gorm/utils 0.134s
? gorm.io/gorm/utils/tests [no test files]
ok gorm.io/gorm/tests 22.010s
testing sqlserver...
ok gorm.io/gorm 0.183s
? gorm.io/gorm/callbacks [no test files]
ok gorm.io/gorm/clause 1.629s
ok gorm.io/gorm/logger 0.153s
? gorm.io/gorm/migrator [no test files]
ok gorm.io/gorm/schema 0.815s
ok gorm.io/gorm/utils 0.135s
? gorm.io/gorm/utils/tests [no test files]
ok gorm.io/gorm/tests 28.078s |
callbacks/associations.go
Outdated
) | ||
selects := make([]string, 0, len(selectColumns)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to keep those codes in the var
group?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to keep those codes in the
var
group?
Thanks for the review!
You're right, I will put it back.
callbacks/associations.go
Outdated
fieldType = rel.Field.FieldType | ||
isPtr = fieldType.Kind() == reflect.Ptr | ||
) | ||
objs := make([]reflect.Value, 0, db.Statement.ReflectValue.Len()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to following code?
var (
objs = make([]reflect.Value, 0, db.Statement.ReflectValue.Len())
fieldType = rel.Field.FieldType
isPtr = fieldType.Kind() == reflect.Ptr
)
there are some similar changes could make
* change the method of initializing slice and fixed the length to be specified as 0 * keep the association.go code in the var group * keep the association.go code in the var group * change to initializing in var group
* change the method of initializing slice and fixed the length to be specified as 0 * keep the association.go code in the var group * keep the association.go code in the var group * change to initializing in var group
What did this pull request do?
Hi, I'm sorry for the trouble I caused you earlier. I'll be careful next time.
This is a small change, but it will send a PR.
There are places where the slice capacity is not specified.
I thought this would be better for Go's slice specification, since the capacity of the slice to be appended can be allocated in advance by the length.