|
|
|
|
|
by archargelod
8 days ago
|
|
Is there any way in Go to selectively turn off bounds checking for a block, function or module? E.g. in Nim I can just do: proc littleEndian(b: openarray[byte]): uint32 =
{.push boundChecks: off.}
return uint32(b[0]) or (uint32(b[1]) shl 8) or (uint32(b[2]) shl 16) or (uint32(b[3]) shl 24)
{.pop.}
And GCC is smart enough to reduce it to a single operation: 000000000000bf80 <littleEndian_u0__session95202695079520951784538200>:
bf80: 8b 07 mov (%rdi),%eax
bf82: c3 ret
|
|