perf: prefer absl::flat_hash_set
over std::unordered_set
(#46374)
* perf: use absl::flat_hash_set in SpellCheckClient::SpellCheckText() Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: use absl::flat_hash_set in MessagePort::DisentanglePorts() Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
15d2a7dc4c
commit
65f9f08187
2 changed files with 6 additions and 5 deletions
|
@ -5,7 +5,6 @@
|
||||||
#include "shell/browser/api/message_port.h"
|
#include "shell/browser/api/message_port.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_set>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "base/containers/to_vector.h"
|
#include "base/containers/to_vector.h"
|
||||||
|
@ -20,6 +19,7 @@
|
||||||
#include "shell/common/gin_helper/event_emitter_caller.h"
|
#include "shell/common/gin_helper/event_emitter_caller.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
#include "shell/common/v8_util.h"
|
#include "shell/common/v8_util.h"
|
||||||
|
#include "third_party/abseil-cpp/absl/container/flat_hash_set.h"
|
||||||
#include "third_party/blink/public/common/messaging/transferable_message.h"
|
#include "third_party/blink/public/common/messaging/transferable_message.h"
|
||||||
#include "third_party/blink/public/common/messaging/transferable_message_mojom_traits.h"
|
#include "third_party/blink/public/common/messaging/transferable_message_mojom_traits.h"
|
||||||
#include "third_party/blink/public/mojom/messaging/transferable_message.mojom.h"
|
#include "third_party/blink/public/mojom/messaging/transferable_message.mojom.h"
|
||||||
|
@ -226,7 +226,8 @@ std::vector<blink::MessagePortChannel> MessagePort::DisentanglePorts(
|
||||||
if (ports.empty())
|
if (ports.empty())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
std::unordered_set<MessagePort*> visited;
|
absl::flat_hash_set<MessagePort*> visited;
|
||||||
|
visited.reserve(ports.size());
|
||||||
|
|
||||||
// Walk the incoming array - if there are any duplicate ports, or null ports
|
// Walk the incoming array - if there are any duplicate ports, or null ports
|
||||||
// or cloned ports, throw an error (per section 8.3.3 of the HTML5 spec).
|
// or cloned ports, throw an error (per section 8.3.3 of the HTML5 spec).
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <unordered_set>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -20,6 +19,7 @@
|
||||||
#include "shell/common/gin_helper/dictionary.h"
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
#include "shell/common/gin_helper/function_template.h"
|
#include "shell/common/gin_helper/function_template.h"
|
||||||
#include "shell/common/gin_helper/microtasks_scope.h"
|
#include "shell/common/gin_helper/microtasks_scope.h"
|
||||||
|
#include "third_party/abseil-cpp/absl/container/flat_hash_set.h"
|
||||||
#include "third_party/blink/public/web/web_text_checking_completion.h"
|
#include "third_party/blink/public/web/web_text_checking_completion.h"
|
||||||
#include "third_party/blink/public/web/web_text_checking_result.h"
|
#include "third_party/blink/public/web/web_text_checking_result.h"
|
||||||
#include "third_party/icu/source/common/unicode/uscript.h"
|
#include "third_party/icu/source/common/unicode/uscript.h"
|
||||||
|
@ -182,9 +182,9 @@ void SpellCheckClient::SpellCheckText() {
|
||||||
|
|
||||||
void SpellCheckClient::OnSpellCheckDone(
|
void SpellCheckClient::OnSpellCheckDone(
|
||||||
const std::vector<std::u16string>& misspelled_words) {
|
const std::vector<std::u16string>& misspelled_words) {
|
||||||
|
const absl::flat_hash_set<std::u16string> misspelled{misspelled_words.begin(),
|
||||||
|
misspelled_words.end()};
|
||||||
std::vector<blink::WebTextCheckingResult> results;
|
std::vector<blink::WebTextCheckingResult> results;
|
||||||
std::unordered_set<std::u16string> misspelled(misspelled_words.begin(),
|
|
||||||
misspelled_words.end());
|
|
||||||
|
|
||||||
auto& word_list = pending_request_param_->wordlist();
|
auto& word_list = pending_request_param_->wordlist();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue