Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => CodeCompletion redesign => Topic started by: ollydbg on April 05, 2009, 01:36:25 pm

Title: Question on Tokenizer::SkipWhiteSpace
Post by: ollydbg on April 05, 2009, 01:36:25 pm
Here is the code
Code
bool Tokenizer::SkipWhiteSpace()
{
    // skip spaces, tabs, etc.
    while (CurrentChar() <= _T(' ') && MoveToNextChar()) // don't check EOF when MoveToNextChar already does, also replace isspace() which calls msvcrt.dll
        ;                                                // with a dirty hack:  CurrentChar() <= ' ' is "good enough" here
    if (IsEOF())
        return false;
    return true;
}

My question is: Why we should avoid a call to msvcrt.dll?

I use "dependency walker" to check "codeblocks.dll", it do depend on msvcrt.dll. See the screen shot.

Any comments? Thanks.

[attachment deleted by admin]
Title: Re: Question on Tokenizer::SkipWhiteSpace
Post by: Ceniza on April 05, 2009, 03:21:06 pm
The idea behind avoiding a call to isspace in msvcrt.dll is for the sake of optimization. Comparing directly with "empty-space" (although it is a dirty hack, as the comment points) is a lot faster than pushing the character, saving all registers, calling the function, comparing the character, restoring all registers and returning. I think it was Thomas who changed that, and it improved performance. No other reasons for it.
Title: Re: Question on Tokenizer::SkipWhiteSpace
Post by: ollydbg on April 05, 2009, 03:50:44 pm
The idea behind avoiding a call to isspace in msvcrt.dll is for the sake of optimization. Comparing directly with "empty-space" (although it is a dirty hack, as the comment points) is a lot faster than pushing the character, saving all registers, calling the function, comparing the character, restoring all registers and returning. I think it was Thomas who changed that, and it improved performance. No other reasons for it.

Thanks for your answer.

By the way, I thought carefully why it didn't use equal comparing instead.
Finally  I realized that

Code
CurrentChar() <= _T(' ')

also skips _T('\n'), that can't be done by calling isspace().