mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-21 13:53:11 -07:00
Use a switch statement instead of an array (#1900)
This makes processing of opCodes faster
This commit is contained in:
parent
5c98b6e53c
commit
6576136465
1 changed files with 24 additions and 10 deletions
|
@ -30,17 +30,31 @@ namespace
|
||||||
// 0 is returned. Higher the number, higher the precedence of the operator.
|
// 0 is returned. Higher the number, higher the precedence of the operator.
|
||||||
int NPrecedenceOfOp(int nopCode)
|
int NPrecedenceOfOp(int nopCode)
|
||||||
{
|
{
|
||||||
static uint16_t rgbPrec[] = { 0, 0, IDC_OR, 0, IDC_XOR, 0, IDC_AND, 1, IDC_NAND, 1, IDC_NOR, 1, IDC_ADD, 2, IDC_SUB, 2, IDC_RSHF, 3,
|
switch (nopCode)
|
||||||
IDC_LSHF, 3, IDC_RSHFL, 3, IDC_MOD, 3, IDC_DIV, 3, IDC_MUL, 3, IDC_PWR, 4, IDC_ROOT, 4, IDC_LOGBASEY, 4 };
|
|
||||||
|
|
||||||
for (unsigned int iPrec = 0; iPrec < size(rgbPrec); iPrec += 2)
|
|
||||||
{
|
{
|
||||||
if (nopCode == rgbPrec[iPrec])
|
default:
|
||||||
{
|
case IDC_OR:
|
||||||
return rgbPrec[iPrec + 1];
|
case IDC_XOR:
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
|
case IDC_AND:
|
||||||
|
case IDC_NAND:
|
||||||
|
case IDC_NOR:
|
||||||
|
return 1;
|
||||||
|
case IDC_ADD:
|
||||||
|
case IDC_SUB:
|
||||||
|
return 2;
|
||||||
|
case IDC_LSHF:
|
||||||
|
case IDC_RSHF:
|
||||||
|
case IDC_RSHFL:
|
||||||
|
case IDC_MOD:
|
||||||
|
case IDC_DIV:
|
||||||
|
case IDC_MUL:
|
||||||
|
return 3;
|
||||||
|
case IDC_PWR:
|
||||||
|
case IDC_ROOT:
|
||||||
|
case IDC_LOGBASEY:
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue