ntdll: rtlstr.c: Implement checking for control characters inRtlIsTextUnicode [try 2]

Rolf Kalbermatter rolf.kalbermatter at citeng.com
Fri Jun 20 02:23:09 CDT 2008


Zac Brown [mailto:zac at zacbrown.org] 
> Rolf Kalbermatter wrote:
> > Dan Kegel [mailto:dank at kegel.com]
> >  
> >> e.g.
> >>
> >>  if (flags & IS_TEXT_UNICODE_CONTROLS)
> >> 	    for (i = 0; i < len; i++)
> >>          switch (s[i]) {
> >>            case '\t':
> >>            case '\n':
> >>            case 'r':
> >>            case 0x20:
> >>                 out_flags |= IS_TEXT_UNICODE_CONTROLS;
> >>                 goto done;
> >>            default:
> >>          }
> >>     }
> >>     done:
> > 
> > Shouldn't a break instead of the goto work too?
> 
> A break will only exit the switch statement which is 
> pointless since we don't care about the rest of the string if 
> we find a control character.

Ah well, you are right of course! But personally I feel about the use
of a switch statement in such a case a bit "overdone". It's not so much
a selection of operations based on a variable as much more a clear
conditional expression such as

    if (expression1 OR
        expresssion2 OR
        ...)
    {
       out_flags |= IS_TEXT_UNICODE_CONTROLS;
       break;
    }

which I think Dan was trying to avoid since he might not like "complex"
conditional expressions. But then I would normally go myself to great
lengths to avoid a goto as I feel bad about the use of them :-)

The fact that s[i] would seem to be evaluated 4 times might look bad
but should be no problem for nowadays optimizing compilers to create
similar code as what a switch statement would produce and could be
also avoided by an incremented character pointer instead of the loop
counter i, which might be even more optimal.

Rolf Kalbermatter




More information about the wine-devel mailing list