Use 'switch' instead of 'if..else if'

This commit is contained in:
Khan M Rashedun-Naby 2018-09-23 17:28:51 +06:00
parent 5dd3ee2d96
commit 376ce07915

View File

@ -106,18 +106,22 @@ bool SemVerMatchExpression::MatchComponent::matches(SemVerVersion const& _versio
} }
if (cmp == 0 && !_version.prerelease.empty() && didCompare) if (cmp == 0 && !_version.prerelease.empty() && didCompare)
cmp = -1; cmp = -1;
if (prefix == Token::Assign)
switch (prefix)
{
case Token::Assign:
return cmp == 0; return cmp == 0;
else if (prefix == Token::LessThan) case Token::LessThan:
return cmp < 0; return cmp < 0;
else if (prefix == Token::LessThanOrEqual) case Token::LessThanOrEqual:
return cmp <= 0; return cmp <= 0;
else if (prefix == Token::GreaterThan) case Token::GreaterThan:
return cmp > 0; return cmp > 0;
else if (prefix == Token::GreaterThanOrEqual) case Token::GreaterThanOrEqual:
return cmp >= 0; return cmp >= 0;
else default:
solAssert(false, "Invalid SemVer expression"); solAssert(false, "Invalid SemVer expression");
}
return false; return false;
} }
} }
@ -196,21 +200,22 @@ SemVerMatchExpression::MatchComponent SemVerMatchExpressionParser::parseMatchCom
{ {
SemVerMatchExpression::MatchComponent component; SemVerMatchExpression::MatchComponent component;
Token::Value token = currentToken(); Token::Value token = currentToken();
if (
token == Token::BitXor || switch (token)
token == Token::BitNot ||
token == Token::LessThan ||
token == Token::LessThanOrEqual||
token == Token::GreaterThan ||
token == Token::GreaterThanOrEqual ||
token == Token::Assign
)
{ {
case Token::BitXor:
case Token::BitNot:
case Token::LessThan:
case Token::LessThanOrEqual:
case Token::GreaterThan:
case Token::GreaterThanOrEqual:
case Token::Assign:
component.prefix = token; component.prefix = token;
nextToken(); nextToken();
} break;
else default:
component.prefix = Token::Assign; component.prefix = Token::Assign;
}
component.levelsPresent = 0; component.levelsPresent = 0;
while (component.levelsPresent < 3) while (component.levelsPresent < 3)