Some minor optimizations to tokenizers (thanks mordante)

Fixed UNLIKELY macro
This commit is contained in:
Pauli Nieminen 2008-02-08 12:48:10 +00:00
parent 743a597fe4
commit dd575a8cf4
2 changed files with 13 additions and 13 deletions

View file

@ -48,10 +48,10 @@ void tokenizer::skip_comment()
}
n = 0;
this->next_char_fast();
while (current_ != EOF && current_ != '\n') {
while (current_ != '\n' && current_ != EOF) {
for (index = matching.begin(); index != matching.end();)
{
if(comment[*index][n] != static_cast<unsigned char>(current_))
if(UNLIKELY(comment[*index][n] != static_cast<unsigned char>(current_)))
{
index = matching.erase(index);
}
@ -67,7 +67,7 @@ void tokenizer::skip_comment()
this->next_char_fast();
} while (current_ == ' ' || current_ == '\t');
textdomain_ = "";
while(current_ != EOF && current_ != '\n')
while(current_ != '\n' && current_ != EOF)
{
textdomain_ += current_;
this->next_char_fast();
@ -79,9 +79,13 @@ void tokenizer::skip_comment()
this->next_char_fast();
} while (current_ == ' ' || current_ == '\t');
std::string lineno;
while(current_ != EOF && current_ != '\n')
while(current_ != '\n' && current_ != EOF)
{
if (current_ == ' ' || current_ == '\t')
if (UNLIKELY(current_ == '\n') || UNLIKELY(current_ == EOF))
{
return;
}
if (UNLIKELY(current_ == ' ') || UNLIKELY(current_ == '\t'))
{
break;
}
@ -90,15 +94,11 @@ void tokenizer::skip_comment()
}
if (current_ == EOF || current_ == '\n')
{
return;
}
do {
this->next_char_fast();
} while (current_ == ' ' || current_ == '\t');
file_ = "";
while (current_ != EOF && current_ != '\n')
while (current_ != '\n' && current_ != EOF)
{
file_ += current_;
this->next_char_fast();
@ -113,7 +113,7 @@ void tokenizer::skip_comment()
}
}
++n;
if (!matching.empty())
if (UNLIKELY(!matching.empty()))
{
break;
}

View file

@ -146,8 +146,8 @@ void push_back(T& str, C c)
}
#ifdef HAVE_BUILTIN_EXPECT
#define LIKELY(a) __builtin_expect((a),1)
#define UNLIKELY(a) __builtin_expect((a),1)
#define LIKELY(a) __builtin_expect((a),1) // Tells GCC to optimize code so that if is likely to happen
#define UNLIKELY(a) __builtin_expect((a),0) // Tells GCC to optimize code so that if is unlikely to happen
#else
#define LIKELY(a) a
#define UNLIKELY(a) a