From 3b40b00004ecbac715a99f251bfb30a00542e21e Mon Sep 17 00:00:00 2001 From: Henry Wilson Date: Sat, 30 Dec 2017 22:58:48 +0000 Subject: [PATCH 07/31] StringFilter::word_index ~> std::vector --- src/stringfilter.cpp | 18 +++++++----------- src/stringfilter_type.h | 6 +++--- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/stringfilter.cpp b/src/stringfilter.cpp index 6045c19ef..1d90c8e8a 100644 --- a/src/stringfilter.cpp +++ b/src/stringfilter.cpp @@ -28,7 +28,7 @@ static const WChar STATE_QUOTE2 = '"'; */ void StringFilter::SetFilterTerm(const char *str) { - this->word_index.Reset(); + Reset(this->word_index); this->word_matches = 0; free(this->filter_buffer); @@ -75,7 +75,7 @@ void StringFilter::SetFilterTerm(const char *str) /* Add to word */ if (word == NULL) { - word = this->word_index.Append(); + word = &*Extend(this->word_index, 1); word->start = dest; word->match = false; } @@ -91,10 +91,7 @@ void StringFilter::SetFilterTerm(const char *str) void StringFilter::ResetState() { this->word_matches = 0; - const WordState *end = this->word_index.End(); - for (WordState *it = this->word_index.Begin(); it != end; ++it) { - it->match = false; - } + for (auto &ws : this->word_index) ws.match = false; } /** @@ -110,11 +107,10 @@ void StringFilter::AddLine(const char *str) if (str == NULL) return; bool match_case = this->case_sensitive != NULL && *this->case_sensitive; - const WordState *end = this->word_index.End(); - for (WordState *it = this->word_index.Begin(); it != end; ++it) { - if (!it->match) { - if ((match_case ? strstr(str, it->start) : strcasestr(str, it->start)) != NULL) { - it->match = true; + for (auto &ws : this->word_index) { + if (not ws.match) { + if ((match_case ? strstr(str, ws.start) : strcasestr(str, ws.start)) != NULL) { + ws.match = true; this->word_matches++; } } diff --git a/src/stringfilter_type.h b/src/stringfilter_type.h index f78b133cb..32432f8b6 100644 --- a/src/stringfilter_type.h +++ b/src/stringfilter_type.h @@ -39,7 +39,7 @@ private: }; const char *filter_buffer; ///< Parsed filter string. Words separated by 0. - SmallVector word_index; ///< Word index and filter state. + std::vector word_index; ///< Word index and filter state. uint word_matches; ///< Summary of filter state: Number of words matched. const bool *case_sensitive; ///< Match case-sensitively (usually a static variable). @@ -58,7 +58,7 @@ public: * Check whether any filter words were entered. * @return true if no words were entered. */ - bool IsEmpty() const { return this->word_index.Length() == 0; } + bool IsEmpty() const { return this->word_index.empty(); } void ResetState(); void AddLine(const char *str); @@ -68,7 +68,7 @@ public: * Get the matching state of the current item. * @return true if matched. */ - bool GetState() const { return this->word_matches == this->word_index.Length(); } + bool GetState() const { return this->word_matches == this->word_index.size(); } }; #endif /* STRINGFILTER_TYPE_H */ -- 2.14.1