Use a switch statement instead of an array

This makes processing of opCodes faster
This commit is contained in:
Rose 2022-09-23 10:12:56 -04:00
commit a5e14ca7cf

View file

@ -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;
}
} }
} }