Hello bearophile,
BCS:
Things I'd use in place of that:
/////
char[] str, int at = 0;
...
switch(str[at]) { ... }
...
at++;
or
/////
char[] str;
...
switch(str[0]) { ... }
...
str = str[1..$];
When in not-debug mode that struct of mine is just 1 word long, so it
hopefully gets optimized well by LDC2. While removing that free 2-word
ling "str" is a bit harder.
Almost all the cases I can think of fall into one of a few categories:
- the length stuff can be statically verified to be correct and the length
need not be carried around
- the length stuff can't be statically verified but the code handles he dynamic
verification in such a way the optimizer can figure out how to safely omit
the length checks for much of the code.
- the length stuff can't be statically verified and there is no way to enforce
correct dynamic verification so you can't safely omit the length and checks
even in release mode.
In each case, the native solution can be just as fast as your solution or
your solution is not safe in release mode.
And it
acts just like a pointer, so you can move it in both directions, etc
I'll give you that point.
--
<IXOYE><