[swift-evolution] Proposal: Remove the "fallthrough" keyword

Kevin Ballard kevin at sb.org
Fri Dec 4 16:57:19 CST 2015


On Fri, Dec 4, 2015, at 02:42 PM, John McCall wrote:
>> On Dec 4, 2015, at 2:33 PM, Kevin Ballard <kevin at sb.org> wrote: It's
>> not actually Duff's Device. Duff's Device relies on the fact that C
>> switch statements don't actually introduce a new scope, and so it
>> overlaps a switch with a do-while loop. This lets it only test the
>> number of bytes once, to jump into the middle of the loop, and then
>> it switches over to a while loop that decrements a counter every 8
>> instructions. Basically, it's a trick for manual loop unrolling that
>> deals with non-multiple-of-8 counts efficiently.
>
> To be pedantic, C switch statements do introduce a new scope.  What
> Duff’s Device exploits is that switch is allowed to jump into
> (almost) arbitrary scopes, and cases can appear anywhere recursively
> inside a switch.

Oh you're right, what I meant to say was that case statements don't
introduce a new scope. The do-while loop is contained entirely within
the scope of the switch itself, and the case statements act like goto
labels so it can jump into the scope of the do-while.

-Kevin Ballard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151204/b0d796bb/attachment.html>


More information about the swift-evolution mailing list