I'm trying to build simple lexical analyzer - lexer. The part I'm working on now is tokenizer. I'm writing function which determines whitespaces (whitespaces, tabs, newlines(CR, LF)) in the input sequence. So the question is which code is more correct:
The code with switch-case statement:
bool isWhitespace(wchar_t &symbol) {
switch (symbol) {
case L' ':
case L'\t':
case L'\r':
case L'\n':
return true;
default:
return false;
}
}
Or the code with if(.. || .. || ..) statement:
bool isWhitespace(wchar_t &symbol) {
if (symbol == L' ' ||
symbol == L'\t' ||
symbol == L'\r' ||
symbol == L'\n') {
return true;
}
return false;
}
And which one would be faster?
Aucun commentaire:
Enregistrer un commentaire