contour-terminal/libunicode

optimize binary search via L1 dcache prefetching using `__builtin_prefetch`

christianparpart opened this issue · 3 comments

auto a = size_t{0};
auto b = static_cast<size_t>(_ranges.size()) - 1;
while (a < b)
{
auto const i = ((b + a) / 2);
auto const& I = _ranges[i];
if (I.to < _codepoint)
a = i + 1;
else if (I.from > _codepoint)
{
if (i == 0)
return false;
b = i - 1;
}
else
return true;
}
return a == b && _ranges[a].from <= _codepoint && _codepoint <= _ranges[a].to;

See: https://stackoverflow.com/a/31688096/386670

I currently have a naive O(log2) implementation. I had a look at some of your proposals and it seems they all cover interesting points. I would love to have a solution that improves table lookup performance.

Can be closed because the new codepoint_properties API (#46) comes with O(1) lookup. The existing API implementations still using binary-search tables will either be removed (other ticket) or rewritten to use the new API.