stream-vbyte-go icon indicating copy to clipboard operation
stream-vbyte-go copied to clipboard

lookup: use byte literal instead of map

Open stapelberg opened this issue 6 years ago • 3 comments

This eliminates a runtime.mapaccess1 call (in favor of a memory access) whereever lookup[ctrl] is used.

stapelberg avatar Apr 03 '18 21:04 stapelberg

I learned that [...]int{10:2} is valid in Go. I don’t think it is in the spec?

lemire avatar Apr 03 '18 22:04 lemire

Both the ... syntax and the usage of keys for an array literal are defined in https://golang.org/ref/spec#Composite_literals:

The key is interpreted as a field name for struct literals, an index for array and slice literals, and a key for map literals.

The notation ... specifies an array length equal to the maximum element index plus one.

I hope that clarifies things :)

stapelberg avatar Apr 04 '18 07:04 stapelberg

Yes, I see it now.

lemire avatar Apr 04 '18 12:04 lemire