perf: remove unnecessary `.c_str()` calls (#41869)

* perf: remove unnecessary c_str() call when invoking promise.RejectWithErrorMessage()

RejectWithErrorMessage() takes a std::string_view

* perf: remove unnecessary c_str() call when invoking Environment::SetVar()

the val arg to Environment::SetVar() takes a const std::string&

* refactor: use string_view variant of base::UTF8ToWide()

* perf: remove unnecessary c_str() call when instantiating a ScopedHString

ScopedHString has always taken a StringPiece

* refactor: use simpler invocation of base::make_span()

* perf: remove unnecessary c_str() call when calling base::CommandLine::HasSwitch()

HasSwitch() already takes a string_piece

* perf: remove unnecessary c_str() call when calling net::HttpResponseHeaders::AddHeader()

AddHeader() already takes a StringPiece arg

* perf: omit unnecessary str -> wstr -> str conversion in DesktopCapturer::UpdateSourcesList()

this conversion was made redundant by c670e38
This commit is contained in:
Charles Kerr 2024-04-16 18:48:54 -05:00 коммит произвёл GitHub
Родитель c670e38b4b
Коммит b428315c6d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
7 изменённых файлов: 8 добавлений и 14 удалений

Просмотреть файл

@ -462,8 +462,7 @@ void OnClientCertificateSelected(
return;
auto certs = net::X509Certificate::CreateCertificateListFromBytes(
base::as_bytes(base::make_span(data.c_str(), data.size())),
net::X509Certificate::FORMAT_AUTO);
base::as_bytes(base::make_span(data)), net::X509Certificate::FORMAT_AUTO);
if (!certs.empty()) {
scoped_refptr<net::X509Certificate> cert(certs[0].get());
for (auto& identity : *identities) {

Просмотреть файл

@ -399,11 +399,7 @@ void DesktopCapturer::UpdateSourcesList(DesktopMediaList* list) {
int device_name_index = 0;
for (auto& source : screen_sources) {
const auto& device_name = device_names[device_name_index++];
std::wstring wide_device_name;
base::UTF8ToWide(device_name.c_str(), device_name.size(),
&wide_device_name);
const int64_t device_id =
base::PersistentHash(base::WideToUTF8(wide_device_name.c_str()));
const int64_t device_id = base::PersistentHash(device_name);
source.display_id = base::NumberToString(device_id);
}
}

Просмотреть файл

@ -313,7 +313,7 @@ int ElectronBrowserMainParts::PreCreateThreads() {
std::string str;
if (env->GetVar("LC_ALL", &str))
lc_all.emplace(std::move(str));
env->SetVar("LC_ALL", locale.c_str());
env->SetVar("LC_ALL", locale);
}
#endif

Просмотреть файл

@ -267,7 +267,7 @@ class AsarURLLoader : public network::mojom::URLLoader {
}
if (head->headers) {
head->headers->AddHeader(net::HttpRequestHeaders::kContentType,
head->mime_type.c_str());
head->mime_type);
}
client_->OnReceiveResponse(std::move(head), std::move(consumer_handle),
std::nullopt);

Просмотреть файл

@ -540,7 +540,7 @@ HRESULT WindowsToastNotification::SetXmlImage(IXmlDocument* doc,
ComPtr<IXmlNode> src_attr;
RETURN_IF_FAILED(attrs->GetNamedItem(src, &src_attr));
ScopedHString img_path(icon_path.c_str());
const ScopedHString img_path{icon_path};
if (!img_path.success())
return E_FAIL;

Просмотреть файл

@ -14,12 +14,11 @@
namespace {
bool HasSwitch(const std::string& name) {
return base::CommandLine::ForCurrentProcess()->HasSwitch(name.c_str());
return base::CommandLine::ForCurrentProcess()->HasSwitch(name);
}
base::CommandLine::StringType GetSwitchValue(const std::string& name) {
return base::CommandLine::ForCurrentProcess()->GetSwitchValueNative(
name.c_str());
return base::CommandLine::ForCurrentProcess()->GetSwitchValueNative(name);
}
void AppendSwitch(const std::string& switch_string,

Просмотреть файл

@ -51,7 +51,7 @@ void OnOpenFinished(gin_helper::Promise<void> promise,
if (error.empty())
promise.Resolve();
else
promise.RejectWithErrorMessage(error.c_str());
promise.RejectWithErrorMessage(error);
}
v8::Local<v8::Promise> OpenExternal(const GURL& url, gin::Arguments* args) {