Skip to content

separate-byte-string-map-key

Detect allocated byte-to-string temporaries used only for map lookups.

Updated View as Markdown

Default severity: warning

The compiler can perform items[string(bytes)] without copying the byte slice because the temporary string cannot escape the lookup. Assigning string(bytes) to a variable first prevents that optimization and allocates when the variable is used only as a map key.

The check stays silent when the string variable has any non-lookup use.

Bad

key := string(keyBytes); value := items[key]

Good

value := items[string(keyBytes)]
Navigation

Type to search…

↑↓ navigate↵ selectEsc close