From cfddf0e9cd2be91e942a55eff2163bf6aefdae23 Mon Sep 17 00:00:00 2001 From: vng Date: Sat, 1 Sep 2012 17:05:19 +0300 Subject: [PATCH] [search] Fix bug with empty search index data. --- indexer/string_file.cpp | 11 ++++++++--- indexer/string_file.hpp | 8 +++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/indexer/string_file.cpp b/indexer/string_file.cpp index 1b411f3340..1d3c976c07 100644 --- a/indexer/string_file.cpp +++ b/indexer/string_file.cpp @@ -56,21 +56,26 @@ void StringsFile::AddString(StringT const & s) m_strings.push_back(s); } +bool StringsFile::IteratorT::IsEnd() const +{ + return m_file.m_queue.empty(); +} + StringsFile::StringT StringsFile::IteratorT::dereference() const { - ASSERT ( !m_file.m_queue.empty(), () ); + ASSERT ( IsValid(), () ); return m_file.m_queue.top().m_string; } void StringsFile::IteratorT::increment() { - ASSERT ( !m_file.m_queue.empty(), () ); + ASSERT ( IsValid(), () ); int const index = m_file.m_queue.top().m_index; m_file.m_queue.pop(); if (!m_file.PushNextValue(index)) - m_end = m_file.m_queue.empty(); + m_end = IsEnd(); } StringsFile::StringsFile(string const & fPath) diff --git a/indexer/string_file.hpp b/indexer/string_file.hpp index 50acece3be..2dce71f103 100644 --- a/indexer/string_file.hpp +++ b/indexer/string_file.hpp @@ -60,14 +60,20 @@ public: StringsFile & m_file; bool m_end; + bool IsEnd() const; + inline bool IsValid() const { return (!m_end && !IsEnd()); } + public: IteratorT(StringsFile & file, bool isEnd) : m_file(file), m_end(isEnd) { + // Additional check in case for empty sequence. + if (!m_end) + m_end = IsEnd(); } StringT dereference() const; - bool equal(IteratorT const & r) const { return m_end == r.m_end; } + bool equal(IteratorT const & r) const { return (m_end == r.m_end); } void increment(); };