Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Unified Diff: components/query_parser/query_parser.cc

Issue 2463683002: Remove stl_util's deletion function use from components/query_parser/. (Closed)
Patch Set: include Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/query_parser/query_parser.h ('k') | components/query_parser/query_parser_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/query_parser/query_parser.cc
diff --git a/components/query_parser/query_parser.cc b/components/query_parser/query_parser.cc
index 260a75afd9f6132664bb8932b0186ae98736422f..c65b06ee2525fb24f1cdc430ec3519afef4a8f3a 100644
--- a/components/query_parser/query_parser.cc
+++ b/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<QueryNode> 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<QueryNode> 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<QueryNodeList*>(children_[i]);
+ QueryNodeList* list_node = static_cast<QueryNodeList*>(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<base::string16>* 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<QueryNodeWord> word_node =
+ base::MakeUnique<QueryNodeWord>(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<QueryNodeList> quotes_node =
+ base::MakeUnique<QueryNodePhrase>();
+ 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.
« no previous file with comments | « components/query_parser/query_parser.h ('k') | components/query_parser/query_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698