http://llvm.org/bugs/show_bug.cgi?id=12563
Bug #: 12563
Summary: Add @switch and @case options to Objective-C
Product: new-bugs
Version: unspecified
Platform: Macintosh
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P
Component: new bugs
AssignedTo: [email protected]
ReportedBy: [email protected]
CC: [email protected]
Classification: Unclassified
I often have code sequences like the following (these are contrived examples,
not actual ones) that could be optimized by the compiler if it supported a
@switch and @case mechanism:
if ([thisNSString isEqualToString:@"firstStringToCheck"])
{
[self doSomethingForFirst];
}
else if ([thisNSString isEqualToString:@"secondStringToCheck"])
{
[self doSomethingForSecond];
}
else if ([thisNSString isEqualToString:@"thirdStringToCheck"])
{
[self doSomethingForThird];
}
else if ([thisNSString isEqualToString:@"fourthStringToCheck"])
{
[self doSomethingForFourth];
}
else
{
[self doSomethingForDefault];
}
If @switch/@case were supported, this could be turned into the following in the
source:
@switch (thisNSString)
{
@case @"firstStringToCheck":
{
[self doSomethingForFirst];
@break;
}
@case @"secondStringToCheck":
{
[self doSomethingForSecond];
@break;
}
@case @"thirdStringToCheck":
{
[self doSomethingForThird];
@break;
}
@case @"fourthStringToCheck":
{
[self doSomethingForFourth];
@break;
}
@default:
{
[self doSomethingForDefault];
@break;
}
}
And the runtime could just pull the method to call for the setup of the @switch
and not have to do that for each succeeding failure test. This could be
extended for NSNumber objects to allow non-integer numeric literals be @case
tests:
@case 2.5d:
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs