Proposal for SentinelInputRange

Steven Schveighoffer schveiguy at yahoo.com
Thu Feb 28 09:18:20 PST 2013


On Thu, 28 Feb 2013 12:02:53 -0500, Walter Bright  
<newshound2 at digitalmars.com> wrote:

> On 2/28/2013 7:40 AM, Steven Schveighoffer wrote:
>> If you look at lexer.c, case 0 is the first test.
>
> No, it is not. It is actually a table lookup - all done in parallel.
>
>      jmp cases[character]
>

You are comparing the assembly output of your solution with uncompiled D  
code.  Apples and oranges.

Quoting directly from  
https://github.com/D-Programming-Language/dmd/blob/master/src/lexer.c#L479:

         switch (*p)
         {
             case 0:

As several others have pointed out, an optimizer can (and some do) make  
this rewrite automatically.

The point is, if the lexer simply requires an input range, and not a  
sentinel input range, it is more flexible for its input.  But when it does  
get called with a sentinel input range, the optimizer can reap the  
benefits.

-Steve


More information about the Digitalmars-d mailing list