FAQ
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 | 3 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 © 2022 Grokbase