XO0916: a string time layout parsed on every call
Reported by xo vet. time.format(t, z, "{year}-{month}") and time.parse walk the layout text on every call: 5.4 and 4.7 of Go’s wall, against 2.0 and 1.9 for the methods of a const Layout (decision 0332), which parses it once. Declare the layout as a constant and call its method. A layout built at run time is not reported, and a cold call can say why with // xo:allow XO0916 REASON on the line or the line above.
Example
fn day(t: time.Time, z: time.Zone) -> Str {
time.format(t, z, "{year}-{month}-{day}")
}Fix
const DAY: time.Layout = time.layout("{year}-{month}-{day}")
fn day(t: time.Time, z: time.Zone) -> Str {
DAY.format(t, z)
}Run xo explain XO0916 for this text in a terminal, or see
section 10.6 of the specification.