| 6736 | |
| 6737 | template<typename T, int S> |
| 6738 | T *ScriptItemList<T, S>::Find(LPCTSTR aName, int *apInsertPos) |
| 6739 | { |
| 6740 | // Using a binary searchable array vs a linked list speeds up dynamic function calls, on average. |
| 6741 | int left, right, mid, result; |
| 6742 | for (left = 0, right = mCount - 1; left <= right;) |
| 6743 | { |
| 6744 | mid = (left + right) / 2; |
| 6745 | result = _tcsicmp(aName, mItem[mid]->mName); // lstrcmpi() is not used: 1) avoids breaking existing scripts; 2) provides consistent behavior across multiple locales; 3) performance. |
| 6746 | if (result > 0) |
| 6747 | left = mid + 1; |
| 6748 | else if (result < 0) |
| 6749 | right = mid - 1; |
| 6750 | else // Match found. |
| 6751 | { |
| 6752 | if (apInsertPos) |
| 6753 | *apInsertPos = mid; |
| 6754 | return mItem[mid]; |
| 6755 | } |
| 6756 | } |
| 6757 | if (apInsertPos) |
| 6758 | *apInsertPos = left; |
| 6759 | return NULL; |
| 6760 | } |
| 6761 | |
| 6762 | |
| 6763 |
no outgoing calls
no test coverage detected