mirror of
https://github.com/golang/go
synced 2024-11-05 15:16:11 -07:00
575b88be8f
Suggestion by dsymonds: Save code not data. Add an extra element to the index array and an if can be eliminated. Old generated code: const _Day_name = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday" var _Day_index = [...]uint8{6, 13, 22, 30, 36, 44, 50} func (i Day) String() string { if i < 0 || i >= Day(len(_Day_index)) { return fmt.Sprintf("Day(%d)", i) } hi := _Day_index[i] lo := uint8(0) if i > 0 { lo = _Day_index[i-1] } return _Day_name[lo:hi] } New generated code: const _Day_name = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday" var _Day_index = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50} func (i Day) String() string { if i < 0 || i+1 >= Day(len(_Day_index)) { return fmt.Sprintf("Day(%d)", i) } return _Day_name[_Day_index[i]:_Day_index[i+1]] } Change-Id: I6f46a4892d5813a12ec1ad01738c6a21c7e45172 Reviewed-on: https://go-review.googlesource.com/1990 Reviewed-by: David Symonds <dsymonds@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> |
||
---|---|---|
.. | ||
testdata | ||
endtoend_test.go | ||
golden_test.go | ||
stringer.go | ||
util_test.go |