chore: improve snakeCasedName performance #1688

Merged
lunny merged 3 commits from performance into master 2020-05-22 02:54:50 +00:00
Showing only changes of commit fdb6765648 - Show all commits

View File

@ -98,7 +98,7 @@ func b2s(b []byte) string {
}
func snakeCasedNameNew(name string) string {
newstr := make([]byte, 0)
newstr := make([]byte, 0, len(name))
Outdated
Review

How about give a length ? make([]byte, 0, len(name))

How about give a length ? `make([]byte, 0, len(name)) `

Done.

goos: darwin
goarch: amd64
pkg: xorm.io/xorm/names
BenchmarkSnakeCasedName-8         313640              3524 ns/op            2328 B/op          9 allocs/op
BenchmarkSnakeCasedNameNew-8     1901515               617 ns/op             576 B/op          2 allocs/op
PASS
ok      xorm.io/xorm/names      2.976s
Done. ``` goos: darwin goarch: amd64 pkg: xorm.io/xorm/names BenchmarkSnakeCasedName-8 313640 3524 ns/op 2328 B/op 9 allocs/op BenchmarkSnakeCasedNameNew-8 1901515 617 ns/op 576 B/op 2 allocs/op PASS ok xorm.io/xorm/names 2.976s ```
Outdated
Review

Sorry, maybe newstr := make([]byte, 0, len(name)+1 is better.

Sorry, maybe `newstr := make([]byte, 0, len(name)+1` is better.
Review

Done

Done
for i := 0; i < len(name); i++ {
c := name[i]
if isUpper := 'A' <= c && c <= 'Z'; isUpper {