http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54505
Bug #: 54505
Summary: RFE: Inline function tables
Classification: Unclassified
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: tree-optimization
AssignedTo: [email protected]
ReportedBy: [email protected]
It is common to see code such as
static const int (*ftable[])(struct context *) = {
[V1] = f1,
[V2] = f2,
...
};
...
{
ftable[nr](context);
}
However, this is less efficient than an equivalent switch () statement since
the calling convention must be observed. Some registers are clobbered, others
must be set to the arguments, and the functions must have a prolog and an
epilogue.
It is easy to recognize the pattern though and convert it into an equivalent
switch:
switch (nr) {
case V1:
f1(context);
break;
case V2:
f2(context);
break;
...
}