Is case after case in a switch efficient?
- by RandomGuy
Just a random question regarding switch case efficiency in case after case; is the following code (assume pseudo code):
function bool isValid(String myString){
switch(myString){
case "stringA":
case "stringB":
case "stringC":
return true;
default:
return false;
}
more efficient than this:
function bool isValid(String myString){
switch(myString){
case "stringA":
return true;
case "stringB":
return true;
case "stringC":
return true;
default:
return false;
}
Or is the performance equal? I'm not thinking in a specific language but if needed let's assume it's Java or C (for this case would be needed to use chars instead of strings).