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

Side by Side Diff: components/bookmarks/browser/titled_url_index.cc

Issue 2883523002: Reduce the memory usage of bookmarks storage (Closed)
Patch Set: MakeUnique Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/bookmarks/browser/titled_url_index.h" 5 #include "components/bookmarks/browser/titled_url_index.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/i18n/unicodestring.h" 10 #include "base/i18n/unicodestring.h"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // Loop through index adding all entries that start with term to 200 // Loop through index adding all entries that start with term to
201 // |prefix_matches|. 201 // |prefix_matches|.
202 TitledUrlNodeSet tmp_prefix_matches; 202 TitledUrlNodeSet tmp_prefix_matches;
203 // If this is the first term, then store the result directly in |matches| 203 // If this is the first term, then store the result directly in |matches|
204 // to avoid calling stl intersection (which requires a copy). 204 // to avoid calling stl intersection (which requires a copy).
205 TitledUrlNodeSet* prefix_matches = 205 TitledUrlNodeSet* prefix_matches =
206 first_term ? matches : &tmp_prefix_matches; 206 first_term ? matches : &tmp_prefix_matches;
207 while (i != index_.end() && 207 while (i != index_.end() &&
208 i->first.size() >= term.size() && 208 i->first.size() >= term.size() &&
209 term.compare(0, term.size(), i->first, 0, term.size()) == 0) { 209 term.compare(0, term.size(), i->first, 0, term.size()) == 0) {
210 #if !defined(OS_ANDROID)
211 prefix_matches->insert(i->second.begin(), i->second.end());
212 #else
213 // Work around a bug in the implementation of std::set::insert in the STL
214 // used on android (http://crbug.com/367050).
215 for (TitledUrlNodeSet::const_iterator n = i->second.begin(); 210 for (TitledUrlNodeSet::const_iterator n = i->second.begin();
216 n != i->second.end(); 211 n != i->second.end(); ++n) {
217 ++n)
218 prefix_matches->insert(prefix_matches->end(), *n); 212 prefix_matches->insert(prefix_matches->end(), *n);
219 #endif 213 }
220 ++i; 214 ++i;
221 } 215 }
222 if (!first_term) { 216 if (!first_term) {
223 *matches = 217 *matches =
224 base::STLSetIntersection<TitledUrlNodeSet>(*prefix_matches, *matches); 218 base::STLSetIntersection<TitledUrlNodeSet>(*prefix_matches, *matches);
225 } 219 }
226 } 220 }
227 return !matches->empty(); 221 return !matches->empty();
228 } 222 }
229 223
(...skipping 21 matching lines...) Expand all
251 // We can get here if the node has the same term more than once. For 245 // We can get here if the node has the same term more than once. For
252 // example, a node with the title 'foo foo' would end up here. 246 // example, a node with the title 'foo foo' would end up here.
253 return; 247 return;
254 } 248 }
255 i->second.erase(node); 249 i->second.erase(node);
256 if (i->second.empty()) 250 if (i->second.empty())
257 index_.erase(i); 251 index_.erase(i);
258 } 252 }
259 253
260 } // namespace bookmarks 254 } // namespace bookmarks
OLDNEW
« no previous file with comments | « components/bookmarks/browser/titled_url_index.h ('k') | components/bookmarks/browser/titled_url_node_sorter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698