From e733310db58160074f574c429d48f8308c0afe17 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 8 Mar 2017 10:28:10 +0100 Subject: BASELINE: Update Chromium to 56.0.2924.122 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I4e04de8f47e47e501c46ed934c76a431c6337ced Reviewed-by: Michael BrĂ¼ning --- chromium/components/query_parser/query_parser.cc | 39 +++++++++++----------- chromium/components/query_parser/query_parser.h | 11 +++--- .../query_parser/query_parser_unittest.cc | 9 ++--- 3 files changed, 28 insertions(+), 31 deletions(-) (limited to 'chromium/components/query_parser') diff --git a/chromium/components/query_parser/query_parser.cc b/chromium/components/query_parser/query_parser.cc index 260a75afd9f..c65b06ee252 100644 --- a/chromium/components/query_parser/query_parser.cc +++ b/chromium/components/query_parser/query_parser.cc @@ -11,7 +11,7 @@ #include "base/i18n/case_conversion.h" #include "base/logging.h" #include "base/macros.h" -#include "base/stl_util.h" +#include "base/memory/ptr_util.h" #include "base/strings/utf_string_conversions.h" namespace query_parser { @@ -156,9 +156,9 @@ class QueryNodeList : public QueryNode { QueryNodeList(); ~QueryNodeList() override; - QueryNodeStarVector* children() { return &children_; } + QueryNodeVector* children() { return &children_; } - void AddChild(QueryNode* node); + void AddChild(std::unique_ptr node); // Remove empty subnodes left over from other parsing. void RemoveEmptySubnodes(); @@ -175,7 +175,7 @@ class QueryNodeList : public QueryNode { protected: int AppendChildrenToString(base::string16* query) const; - QueryNodeStarVector children_; + QueryNodeVector children_; private: DISALLOW_COPY_AND_ASSIGN(QueryNodeList); @@ -184,11 +184,10 @@ class QueryNodeList : public QueryNode { QueryNodeList::QueryNodeList() {} QueryNodeList::~QueryNodeList() { - base::STLDeleteElements(&children_); } -void QueryNodeList::AddChild(QueryNode* node) { - children_.push_back(node); +void QueryNodeList::AddChild(std::unique_ptr node) { + children_.push_back(std::move(node)); } void QueryNodeList::RemoveEmptySubnodes() { @@ -196,12 +195,11 @@ void QueryNodeList::RemoveEmptySubnodes() { if (children_[i]->IsWord()) continue; - QueryNodeList* list_node = static_cast(children_[i]); + QueryNodeList* list_node = static_cast(children_[i].get()); list_node->RemoveEmptySubnodes(); if (list_node->children()->empty()) { children_.erase(children_.begin() + i); --i; - delete list_node; } } } @@ -237,8 +235,7 @@ void QueryNodeList::AppendWords(std::vector* words) const { int QueryNodeList::AppendChildrenToString(base::string16* query) const { int num_words = 0; - for (QueryNodeStarVector::const_iterator node = children_.begin(); - node != children_.end(); ++node) { + for (auto node = children_.begin(); node != children_.end(); ++node) { if (node != children_.begin()) query->push_back(L' '); num_words += (*node)->AppendToSQLiteQuery(query); @@ -358,14 +355,14 @@ void QueryParser::ParseQueryWords(const base::string16& query, void QueryParser::ParseQueryNodes(const base::string16& query, MatchingAlgorithm matching_algorithm, - QueryNodeStarVector* nodes) { + QueryNodeVector* nodes) { QueryNodeList root; if (ParseQueryImpl(base::i18n::ToLower(query), matching_algorithm, &root)) nodes->swap(*root.children()); } bool QueryParser::DoesQueryMatch(const base::string16& text, - const QueryNodeStarVector& query_nodes, + const QueryNodeVector& query_nodes, Snippet::MatchPositions* match_positions) { if (query_nodes.empty()) return false; @@ -396,7 +393,7 @@ bool QueryParser::DoesQueryMatch(const base::string16& text, } bool QueryParser::DoesQueryMatch(const QueryWordVector& query_words, - const QueryNodeStarVector& query_nodes) { + const QueryNodeVector& query_nodes) { if (query_nodes.empty() || query_words.empty()) return false; @@ -426,17 +423,19 @@ bool QueryParser::ParseQueryImpl(const base::string16& query, // is not necessarily a word, but could also be a sequence of punctuation // or whitespace. if (iter.IsWord()) { - QueryNodeWord* word_node = new QueryNodeWord(iter.GetString(), - matching_algorithm); + std::unique_ptr word_node = + base::MakeUnique(iter.GetString(), matching_algorithm); if (in_quotes) word_node->set_literal(true); - query_stack.back()->AddChild(word_node); + query_stack.back()->AddChild(std::move(word_node)); } else { // Punctuation. if (IsQueryQuote(query[iter.prev()])) { if (!in_quotes) { - QueryNodeList* quotes_node = new QueryNodePhrase; - query_stack.back()->AddChild(quotes_node); - query_stack.push_back(quotes_node); + std::unique_ptr quotes_node = + base::MakeUnique(); + QueryNodeList* quotes_node_ptr = quotes_node.get(); + query_stack.back()->AddChild(std::move(quotes_node)); + query_stack.push_back(quotes_node_ptr); in_quotes = true; } else { query_stack.pop_back(); // Stop adding to the quoted phrase. diff --git a/chromium/components/query_parser/query_parser.h b/chromium/components/query_parser/query_parser.h index a6e2d229ea1..5e3f18b26e6 100644 --- a/chromium/components/query_parser/query_parser.h +++ b/chromium/components/query_parser/query_parser.h @@ -7,6 +7,7 @@ #include +#include #include #include "base/macros.h" @@ -34,7 +35,7 @@ enum class MatchingAlgorithm { ALWAYS_PREFIX_SEARCH, }; -typedef std::vector QueryWordVector; +using QueryWordVector = std::vector; // QueryNode is used by QueryParser to represent the elements that constitute a // query. While QueryNode is exposed by way of ParseQuery, it really isn't meant @@ -67,7 +68,7 @@ class QueryNode { virtual void AppendWords(std::vector* words) const = 0; }; -typedef std::vector QueryNodeStarVector; +using QueryNodeVector = std::vector>; // This class is used to parse queries entered into the history search into more // normalized queries that can be passed to the SQLite backend. @@ -105,19 +106,19 @@ class QueryParser { // the nodes passes to the caller. void ParseQueryNodes(const base::string16& query, MatchingAlgorithm matching_algorithm, - QueryNodeStarVector* nodes); + QueryNodeVector* nodes); // Returns true if the string text matches the query nodes created by a call // to ParseQuery. If the query does match, each of the matching positions in // the text is added to |match_positions|. bool DoesQueryMatch(const base::string16& text, - const QueryNodeStarVector& nodes, + const QueryNodeVector& nodes, Snippet::MatchPositions* match_positions); // Returns true if all of the |words| match the query |nodes| created by a // call to ParseQuery. bool DoesQueryMatch(const QueryWordVector& words, - const QueryNodeStarVector& nodes); + const QueryNodeVector& nodes); // Extracts the words from |text|, placing each word into |words|. void ExtractQueryWords(const base::string16& text, diff --git a/chromium/components/query_parser/query_parser_unittest.cc b/chromium/components/query_parser/query_parser_unittest.cc index c99c639b964..e99bf5a1101 100644 --- a/chromium/components/query_parser/query_parser_unittest.cc +++ b/chromium/components/query_parser/query_parser_unittest.cc @@ -5,7 +5,6 @@ #include #include "base/macros.h" -#include "base/memory/scoped_vector.h" #include "base/strings/utf_string_conversions.h" #include "components/query_parser/query_parser.h" #include "testing/gtest/include/gtest/gtest.h" @@ -123,15 +122,13 @@ TEST_F(QueryParserTest, ParseQueryNodesAndMatch) { }; for (size_t i = 0; i < arraysize(data); ++i) { QueryParser parser; - ScopedVector query_nodes; + query_parser::QueryNodeVector query_nodes; parser.ParseQueryNodes(base::UTF8ToUTF16(data[i].query), - MatchingAlgorithm::DEFAULT, - &query_nodes.get()); + MatchingAlgorithm::DEFAULT, &query_nodes); Snippet::MatchPositions match_positions; ASSERT_EQ(data[i].matches, parser.DoesQueryMatch(base::UTF8ToUTF16(data[i].text), - query_nodes.get(), - &match_positions)); + query_nodes, &match_positions)); size_t offset = 0; if (data[i].m1_start != 0 || data[i].m1_end != 0) { ASSERT_TRUE(match_positions.size() >= 1); -- cgit v1.2.1