Skip to content
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

Merged
merged 4 commits into from
Mar 4, 2021
Merged

change the method of initializing slice #4097

merged 4 commits into from
Mar 4, 2021

Conversation

sivchari
Copy link
Contributor

  • Do only one thing
  • Non breaking API changes
  • Tested

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.

@sivchari
Copy link
Contributor Author

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

)
selects := make([]string, 0, len(selectColumns))
Copy link
Member

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?

Copy link
Contributor Author

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.

fieldType = rel.Field.FieldType
isPtr = fieldType.Kind() == reflect.Ptr
)
objs := make([]reflect.Value, 0, db.Statement.ReflectValue.Len())
Copy link
Member

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

@jinzhu jinzhu merged commit adf85d5 into go-gorm:master Mar 4, 2021
mittwillson pushed a commit to itering/gorm that referenced this pull request Sep 27, 2021
* 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
cgxxv pushed a commit to cgxxv/gorm that referenced this pull request Mar 25, 2022
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants