refactor: prefer base::circular_deque over std::deque (#47193)

* refactor: use base::circular_deque in ResolveProxyHelper

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use base::circular_deque in GetExtraCrashKeys()

refactor: reduce visibility of kMaxCrashKeyValueSize

This change is to match Chromium's usage advice from
base/containers/README.md: `base:circular_deque` is preferred over
`std::deque` to provide consistent performance across platforms.

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:
trop[bot] 2025-05-21 15:49:06 -05:00 committed by GitHub
commit 2d71d65415
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 13 deletions

View file

@ -5,10 +5,10 @@
#ifndef ELECTRON_SHELL_BROWSER_NET_RESOLVE_PROXY_HELPER_H_ #ifndef ELECTRON_SHELL_BROWSER_NET_RESOLVE_PROXY_HELPER_H_
#define ELECTRON_SHELL_BROWSER_NET_RESOLVE_PROXY_HELPER_H_ #define ELECTRON_SHELL_BROWSER_NET_RESOLVE_PROXY_HELPER_H_
#include <deque>
#include <optional> #include <optional>
#include <string> #include <string>
#include "base/containers/circular_deque.h"
#include "base/memory/raw_ptr.h" #include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/receiver.h"
@ -66,7 +66,7 @@ class ResolveProxyHelper
// Self-reference. Owned as long as there's an outstanding proxy lookup. // Self-reference. Owned as long as there's an outstanding proxy lookup.
scoped_refptr<ResolveProxyHelper> owned_self_; scoped_refptr<ResolveProxyHelper> owned_self_;
std::deque<PendingRequest> pending_requests_; base::circular_deque<PendingRequest> pending_requests_;
// Receiver for the currently in-progress request, if any. // Receiver for the currently in-progress request, if any.
mojo::Receiver<network::mojom::ProxyLookupClient> receiver_{this}; mojo::Receiver<network::mojom::ProxyLookupClient> receiver_{this};

View file

@ -5,11 +5,11 @@
#include "shell/common/crash_keys.h" #include "shell/common/crash_keys.h"
#include <cstdint> #include <cstdint>
#include <deque>
#include <map> #include <map>
#include <string> #include <string>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/containers/circular_deque.h"
#include "base/environment.h" #include "base/environment.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
@ -28,19 +28,17 @@ namespace electron::crash_keys {
namespace { namespace {
auto& GetExtraCrashKeys() {
constexpr size_t kMaxCrashKeyValueSize = 20320; constexpr size_t kMaxCrashKeyValueSize = 20320;
static_assert(kMaxCrashKeyValueSize < crashpad::Annotation::kValueMaxSize, static_assert(kMaxCrashKeyValueSize < crashpad::Annotation::kValueMaxSize,
"max crash key value length above what crashpad supports"); "max crash key value length above what crashpad supports");
using CrashKeyString = crash_reporter::CrashKeyString<kMaxCrashKeyValueSize>;
using ExtraCrashKeys = static base::NoDestructor<base::circular_deque<CrashKeyString>> extra_keys;
std::deque<crash_reporter::CrashKeyString<kMaxCrashKeyValueSize>>;
ExtraCrashKeys& GetExtraCrashKeys() {
static base::NoDestructor<ExtraCrashKeys> extra_keys;
return *extra_keys; return *extra_keys;
} }
std::deque<std::string>& GetExtraCrashKeyNames() { auto& GetExtraCrashKeyNames() {
static base::NoDestructor<std::deque<std::string>> crash_key_names; static base::NoDestructor<base::circular_deque<std::string>> crash_key_names;
return *crash_key_names; return *crash_key_names;
} }