Proposal for SentinelInputRange
Timon Gehr
timon.gehr at gmx.ch
Thu Feb 28 14:16:07 PST 2013
On 02/28/2013 10:40 PM, Walter Bright wrote:
> On 2/28/2013 9:05 AM, deadalnix wrote:
>> I see nothing that can't be done by an optimizing compiler. Maybe
>> something is,
>> but I can't find it. And the example you pointed me aren't.
>
> Tell me how front() will be optimized out to this.
>
> case '>':
> p++;
> if (*p == '=')
> { p++;
> t->value = TOKge; // >=
> }
> else if (*p == '>')
> { p++;
> if (*p == '=')
> { p++;
> t->value = TOKshrass; // >>=
> }
> else if (*p == '>')
> { p++;
> if (*p == '=')
> { p++;
> t->value = TOKushrass; // >>>=
> }
> else
> t->value = TOKushr; // >>>
> }
> else
> t->value = TOKshr; // >>
> }
> else
> t->value = TOKgt; // >
> return;
I'd be surprised if DMD couldn't do it already.
assume: popFront(){ p++; }, front()=>*p, empty()=>*p=='\0'
case '>':
popFront();
if(!empty && front == '='){
popFront();
t->value = TOKge; // >=
}else if(!empty && front == '>'){
popFront();
if(!empty && front == '='){
popFront();
t->value = TOKshrass; // >>=
}else if(!empty && front == '>'){
popFront();
if(!empty && front == '='){
popFront();
t->value = TOKushrass; // >>>=
}else t->value = TOKushr; // >>>
}else t->value = TOKshr; // >>
}else t->value = TOKgt; // >
return;
// inlining =>
case '>':
p++;
if(!(*p=='\0') && *p == '='){
p++;
t->value = TOKge; // >=
}else if(!(*p=='\0') && *p == '>'){
p++;
if(!(*p=='\0') && *p == '='){
p++;
t->value = TOKshrass; // >>=
}else if(!(*p=='\0') && *p == '>'){
p++;
if(!(*p=='\0') && *p == '='){
p++;
t->value = TOKushrass; // >>>=
}else t->value = TOKushr; // >>>
}else t->value = TOKshr; // >>
}else t->value = TOKgt; // >
return;
// expression simplification
// (eg. trivial peephole for x!=a && x==b case sufficient)
// =>
case '>':
p++;
if(*p == '='){
p++;
t->value = TOKge; // >=
}else if(*p == '>'){
p++;
if(*p == '='){
p++;
t->value = TOKshrass; // >>=
}else if(*p == '>'){
p++;
if(*p == '='){
p++;
t->value = TOKushrass; // >>>=
}else t->value = TOKushr; // >>>
}else t->value = TOKshr; // >>
}else t->value = TOKgt; // >
return;
More information about the Digitalmars-d
mailing list