| 7329 | |
| 7330 | |
| 7331 | VarEntry *Script::GetBuiltInVar(LPCTSTR aVarName) |
| 7332 | { |
| 7333 | // This array approach saves about 9KB on code size over the old approach |
| 7334 | // of a series of if's and _tcscmp calls, and performs about the same. |
| 7335 | // The "A_" prefix is omitted from each name string to reduce code size. |
| 7336 | if ((aVarName[0] == 'A' || aVarName[0] == 'a') && aVarName[1] == '_') |
| 7337 | aVarName += 2; |
| 7338 | else |
| 7339 | return nullptr; |
| 7340 | // Using binary search vs. linear search performs a bit better (notably for |
| 7341 | // rare/contrived cases like A_x%index%) and doesn't affect code size much. |
| 7342 | int left, right, mid, result; |
| 7343 | for (left = 0, right = _countof(g_BIV_A) - 1; left <= right;) |
| 7344 | { |
| 7345 | mid = (left + right) / 2; |
| 7346 | result = _tcsicmp(aVarName, g_BIV_A[mid].name); |
| 7347 | if (result > 0) |
| 7348 | left = mid + 1; |
| 7349 | else if (result < 0) |
| 7350 | right = mid - 1; |
| 7351 | else // Match found. |
| 7352 | return &g_BIV_A[mid]; |
| 7353 | } |
| 7354 | // Since above didn't return: |
| 7355 | return nullptr; |
| 7356 | } |
| 7357 | |
| 7358 | |
| 7359 |
nothing calls this directly
no outgoing calls
no test coverage detected