-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
FixedA PR has been merged for this issueA PR has been merged for this issueHelp WantedYou can do thisYou can do thisIn DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Consider the following enum definition:
enum Flags {
A = 1,
B = 2,
C = A | B // Should be constant folded to 3.
}
In most cases, JS engines can optimize simple expressions like these. But they can't do much about accesses to Flags.C
.
switch (x) {
case Flags.A: ... break; // Compiled as case 1: ...
case Flags.B: ... break; // Compiled as case 2: ...
case Flags.C: ... break; // Compiled as Flags.C: ...
}
This prevents JS engines from using a table jump and causes them to fall back on a sequential if/else if implementation for the switch which is all sorts of terrible.
Metadata
Metadata
Assignees
Labels
FixedA PR has been merged for this issueA PR has been merged for this issueHelp WantedYou can do thisYou can do thisIn DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript