FAQ
Another common example in my code

for len(a) > 8 {
      // this should generate zero bound checks
      data := binary.LittleEndian.Uint64(a)

      // and should eventually generate code equivalent to:
      // data := *(*uint64)(unsafe.Pointer(&a[0]))

}
On Thursday, March 10, 2016 at 7:16:35 PM UTC+1, Giovanni Bajo wrote:

In general, it would be great if a dominant check on len(slice) would
eliminate bound checks on dominated accesses, including those in loops.

For instance:

if len(a) < 128 {
panic("programming error")
}

// Now we know that a is at least 128, so the following loop should
// generate zero bound checks
for i := 0; i < 128; i++ {
a[i] = whatever
}


Giovanni

On Thursday, March 10, 2016 at 5:36:06 PM UTC+1, Alexandru Moșoi wrote:

Hi,

Can the bounds checks be eliminated for "if len(a) >= i+2 && a[:i+2]"
(assume i is non-negative)?

This pattern is very common, see for example: nextStdChunk in
time/format.go <https://golang.org/src/time/format.go>. I think the code
is buggy in the extreme case when i+2 overflows. If that's the case, should
we fix the code?

Regards,
--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 38 | next ›
Discussion Overview
groupgolang-dev @
categoriesgo
postedMar 10, '16 at 4:36p
activeMar 21, '16 at 1:09p
posts38
users11
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase