[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 08:42:50 CDT 2011


2011/10/4 Eric Pouech <eric.pouech at orange.fr>:
>
>
> Le 4 octobre 2011 13:40, Frédéric Delanoy <frederic.delanoy at gmail.com> a
> écrit :
>>
>> 2011/10/4 Dan Kegel <dank at kegel.com>:
>> > + * handle_type: type of hIn handle
>> > + *              0 if file, 1 if console, anything else if unknown
>> > (autodetect)
>> >
>> > I suspect you want an enum for that.
>>
>> Well I thought about that, but found it a bit overkill for such a
>> limited set of possible values.
>> Also, if I used sthg like
>>
>> enum CMD_HANDLE_TYPE {
>>   CMD_HT_FILE = 0,
>>   CMD_HT_CONSOLE = 1,
>>   CMD_HT_UNKNOWN = 2
>> }
>>
> again, this is not needed (passing all thoses CMD_HT bits)
>
> static inline BOOL is_console_handle(HANDLE h) {return ((DWORD_PTR)h) & 3 ==
> 3;}
> will test every handle and tell whether it's a console or a regular (file,
> pipe...) handle
>
> Eric Pouech

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?)



More information about the wine-devel mailing list