[1/4] cmd: Avoid checking handle type when already known in WCMD_ReadFile

Frédéric Delanoy frederic.delanoy at gmail.com
Tue Oct 4 13:25:05 CDT 2011


2011/10/4 Juan Lang <juan.lang at gmail.com>:
>> OK but the purpose is to avoid checking the handle type for every line
>> read. Granted, one could use '((DWORD_PTR)h) & 3 == 3' instead of
>> GetConsoleMode or similar function.
>> (there's currently code like "BOOL is_console = GetConsoleMode(...);
>> ...; while WCMD_fgets(..., is_console)" and the handle type shouldn't
>> change between lines/iterations, so why bother recomputing it every
>> time?)
>
> You're probably not.  The compiler will probably inline this function,
> or at least its return value, since it knows it's guaranteed not to
> change.  Please don't do the compiler's work for it:  IMHO, it's more
> readable to make an inline function to determine whether the handle is
> a console handle.

I don't quite understand what you mean. WCMD_ReadFile is called
directly/indirectly in a lot of places, mostly around line-by-line
reads.
The question is not whether the compiler will inline this function
(you can't know that for sure, think -O0, different compilers, etc.),
but whether you want to check that every time.

This function is_console_handle() could be inlined or not/fast, but
that's not the point. The point is why would one want to run that
function when not necessary, i.e. when callers already know the type.
It's just about finding/detecting the handle type once and only once
(per handle).



More information about the wine-devel mailing list