Optimize Volnitsky by inlining compare function

This commit is contained in:
Danila Kutenin 2019-03-30 12:39:45 +03:00
parent 957d23267b
commit 18d3813ff9
2 changed files with 8 additions and 9 deletions

View File

@ -156,7 +156,7 @@ public:
#endif #endif
} }
bool compare(const UInt8 * pos) const ALWAYS_INLINE bool compare(const UInt8 * pos) const
{ {
static const Poco::UTF8Encoding utf8; static const Poco::UTF8Encoding utf8;
@ -374,7 +374,7 @@ public:
#endif #endif
} }
bool compare(const UInt8 * pos) const ALWAYS_INLINE bool compare(const UInt8 * pos) const
{ {
#ifdef __SSE4_1__ #ifdef __SSE4_1__
if (pageSafe(pos)) if (pageSafe(pos))
@ -568,7 +568,7 @@ public:
#endif #endif
} }
bool compare(const UInt8 * pos) const ALWAYS_INLINE bool compare(const UInt8 * pos) const
{ {
#ifdef __SSE4_1__ #ifdef __SSE4_1__
if (pageSafe(pos)) if (pageSafe(pos))

View File

@ -173,10 +173,7 @@ struct PositionImpl
/// We check that the entry does not pass through the boundaries of strings. /// We check that the entry does not pass through the boundaries of strings.
if (pos + needle.size() < begin + offsets[i]) if (pos + needle.size() < begin + offsets[i])
{ res[i] = 1 + Impl::countChars(reinterpret_cast<const char *>(begin + offsets[i - 1]), reinterpret_cast<const char *>(pos));
size_t prev_offset = i != 0 ? offsets[i - 1] : 0;
res[i] = 1 + Impl::countChars(reinterpret_cast<const char *>(begin + prev_offset), reinterpret_cast<const char *>(pos));
}
else else
res[i] = 0; res[i] = 0;
@ -306,7 +303,8 @@ struct MultiSearchAllPositionsImpl
const std::vector<StringRef> & needles, const std::vector<StringRef> & needles,
PaddedPODArray<UInt64> & res) PaddedPODArray<UInt64> & res)
{ {
auto res_callback = [](const UInt8 * start, const UInt8 * end) -> UInt64 { auto res_callback = [](const UInt8 * start, const UInt8 * end) -> UInt64
{
return 1 + Impl::countChars(reinterpret_cast<const char *>(start), reinterpret_cast<const char *>(end)); return 1 + Impl::countChars(reinterpret_cast<const char *>(start), reinterpret_cast<const char *>(end));
}; };
Impl::createMultiSearcherInBigHaystack(needles).searchAllPositions(haystack_data, haystack_offsets, res_callback, res); Impl::createMultiSearcherInBigHaystack(needles).searchAllPositions(haystack_data, haystack_offsets, res_callback, res);
@ -341,7 +339,8 @@ struct MultiSearchFirstPositionImpl
const std::vector<StringRef> & needles, const std::vector<StringRef> & needles,
PaddedPODArray<UInt64> & res) PaddedPODArray<UInt64> & res)
{ {
auto res_callback = [](const UInt8 * start, const UInt8 * end) -> UInt64 { auto res_callback = [](const UInt8 * start, const UInt8 * end) -> UInt64
{
return 1 + Impl::countChars(reinterpret_cast<const char *>(start), reinterpret_cast<const char *>(end)); return 1 + Impl::countChars(reinterpret_cast<const char *>(start), reinterpret_cast<const char *>(end));
}; };
Impl::createMultiSearcherInBigHaystack(needles).searchFirstPosition(haystack_data, haystack_offsets, res_callback, res); Impl::createMultiSearcherInBigHaystack(needles).searchFirstPosition(haystack_data, haystack_offsets, res_callback, res);