From 2912d06cb2d96dcf6026fc16973e65bac4847385 Mon Sep 17 00:00:00 2001 From: Maxim Pimenov Date: Wed, 30 May 2018 00:16:16 +0300 Subject: [PATCH] [search] Switch back to templated token serialization in MemTextIndex. --- search/base/text_index.hpp | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/search/base/text_index.hpp b/search/base/text_index.hpp index aa22a104b1..6fcbc6b4fb 100644 --- a/search/base/text_index.hpp +++ b/search/base/text_index.hpp @@ -201,32 +201,19 @@ private: } template - static void SerializeToken(Sink & sink, std::string const & token) - { - CHECK(!token.empty(), ()); - sink.Write(token.data(), token.size()); - } - - template - static void SerializeToken(Sink & sink, strings::UniString const & token) + static void SerializeToken(Sink & sink, Token const & token) { CHECK(!token.empty(), ()); // todo(@m) Endianness. - sink.Write(token.data(), token.size() * sizeof(strings::UniString::value_type)); + sink.Write(token.data(), token.size() * sizeof(typename Token::value_type)); } template - static void DeserializeToken(Source & source, std::string & token, size_t size) + static void DeserializeToken(Source & source, Token & token, size_t size) { - token.resize(size); - source.Read(&token[0], size); - } - - template - static void DeserializeToken(Source & source, strings::UniString & token, size_t size) - { - ASSERT_EQUAL(size % sizeof(strings::UniString::value_type), 0, ()); - token.resize(size / sizeof(strings::UniString::value_type)); + CHECK_GREATER(size, 0, ()); + ASSERT_EQUAL(size % sizeof(typename Token::value_type), 0, ()); + token.resize(size / sizeof(typename Token::value_type)); source.Read(&token[0], size); } @@ -276,8 +263,8 @@ private: { CHECK_EQUAL(source.Pos(), startPos + header.m_postingsStartsOffset, ()); std::vector postingsStarts(header.m_numTokens + 1); - for (size_t i = 0; i < postingsStarts.size(); ++i) - postingsStarts[i] = ReadPrimitiveFromSource(source); + for (uint32_t & start : postingsStarts) + start = ReadPrimitiveFromSource(source); CHECK_EQUAL(source.Pos(), startPos + header.m_postingsListsOffset, ()); m_postingsByToken.clear();