Skip to content

Commit

Permalink
Use lambdas instead of casts for selecting function overloads.
Browse files Browse the repository at this point in the history
This seemed to be preferred by other people. I bow to the will of the
masses.

Bug: 1368812
Change-Id: I35d9f41185541684a9359b0879ae5bfb01415d9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4328407
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1115551}
  • Loading branch information
pkasting authored and Chromium LUCI CQ committed Mar 10, 2023
1 parent b133a79 commit 2f1b3da
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 54 deletions.
10 changes: 5 additions & 5 deletions cc/slim/nine_patch_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ void NinePatchLayer::AppendQuads(viz::CompositorRenderPass& render_pass,
quad_generator_.SetLayout(image_bounds, bounds(), aperture_, border_,
kOcclusion, fill_center_, nearest_neighbor_);
const bool opaque = layer_tree_impl->IsUIResourceOpaque(resource_id());
// Select the int instead of float version.
auto IntersectRects =
static_cast<gfx::Rect (*)(const gfx::Rect&, const gfx::Rect&)>(
gfx::IntersectRects);
quad_generator_.AppendQuads(
viz_resource_id, opaque,
base::BindRepeating(IntersectRects, quad_state->visible_quad_layer_rect),
base::BindRepeating(
// Select the int instead of float version.
static_cast<gfx::Rect (*)(const gfx::Rect&, const gfx::Rect&)>(
gfx::IntersectRects),
quad_state->visible_quad_layer_rect),
layer_tree_impl->GetClientResourceProvider(), &render_pass, quad_state,
quad_generator_.GeneratePatches());
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ash/printing/zeroconf_printer_detector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ bool ConvertToPrinter(const std::string& service_type,
if (!metadata.pdl.empty()) {
// Per Bonjour Printer Spec v1.2 section 9.2.8, it is invalid for the pdl to
// end with a comma.
auto media_types = base::SplitString(
auto media_types = base::SplitStringPiece(
metadata.pdl, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
if (!media_types.empty() && !media_types.back().empty()) {
// Prune any empty splits.
Expand All @@ -244,7 +244,7 @@ bool ConvertToPrinter(const std::string& service_type,
media_types,
std::back_inserter(
detected_printer->ppd_search_data.supported_document_formats),
static_cast<std::string (*)(base::StringPiece)>(&base::ToLowerASCII));
[](base::StringPiece s) { return base::ToLowerASCII(s); });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ class CorbAndCorsExtensionBrowserTest : public CorbAndCorsExtensionTestBase {
console_observer.messages();

std::vector<std::string> messages;
base::ranges::transform(
console_messages, std::back_inserter(messages),
static_cast<std::string (*)(base::StringPiece16)>(&base::UTF16ToUTF8),
&ConsoleMessage::message);
base::ranges::transform(console_messages, std::back_inserter(messages),
[](const auto& console_message) {
return base::UTF16ToUTF8(console_message.message);
});

// We allow more than 1 console message, because the test might flakily see
// extra console messages - see https://crbug.com/1085629.
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/pdf/pdf_extension_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ testing::AssertionResult EnsurePDFHasLoaded(

if (wait_for_hit_test_data) {
frame.render_frame_host()->ForEachRenderFrameHost(
static_cast<void (*)(content::RenderFrameHost*)>(
&content::WaitForHitTestData));
[](content::RenderFrameHost* render_frame_host) {
return content::WaitForHitTestData(render_frame_host);
});
}

return load_success ? testing::AssertionSuccess()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,10 @@ void ProfileDiscardOptOutListHelper::ProfileDiscardOptOutTracker::
// list of patterns to exclude from discarding.
base::ranges::transform(
user_value_list, std::back_inserter(patterns),
static_cast<const std::string& (base::Value::*)() const>(
&base::Value::GetString));
[](const auto& user_value) { return user_value.GetString(); });
base::ranges::transform(
managed_value_list, std::back_inserter(patterns),
static_cast<const std::string& (base::Value::*)() const>(
&base::Value::GetString));
[](const auto& managed_value) { return managed_value.GetString(); });

delegate_->SetPatterns(browser_context_id_, patterns);
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/webui/omnibox/omnibox_page_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ struct TypeConverter<mojom::AutocompleteMatchPtr, AutocompleteMatch> {
subtypes_str.push_back(base::NumberToString(type));
base::ranges::transform(
subtypes, std::back_inserter(subtypes_str),
static_cast<std::string (*)(int)>(base::NumberToString));
[](int subtype) { return base::NumberToString(subtype); });
result->aqs_type_subtypes = base::JoinString(subtypes_str, ",");
result->has_tab_match = input.has_tab_match.value_or(false);
if (input.associated_keyword.get()) {
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/win/ui_automation_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ std::string IntArrayToString(const std::vector<int32_t>& values) {
std::vector<std::string> value_strings;
base::ranges::transform(
values, std::back_inserter(value_strings),
static_cast<std::string (*)(int)>(&base::NumberToString));
[](int32_t value) { return base::NumberToString(value); });
return base::JoinString(value_strings, ", ");
#else // DCHECK_IS_ON()
return std::string();
Expand Down
5 changes: 3 additions & 2 deletions components/autofill/core/browser/autofill_test_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1186,8 +1186,9 @@ void AddFieldPredictionsToForm(
std::vector<FieldPrediction> field_predictions;
field_predictions.reserve(field_types.size());
base::ranges::transform(field_types, std::back_inserter(field_predictions),
static_cast<FieldPrediction (*)(ServerFieldType)>(
&CreateFieldPrediction));
[](ServerFieldType field_type) {
return CreateFieldPrediction(field_type);
});
return AddFieldPredictionsToForm(field_data, field_predictions,
form_suggestion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ std::string GetNormalizedLocale(const std::string& raw_locale) {
locale.erase(std::remove(locale.begin(), locale.end(), c), locale.end());

base::ranges::transform(locale, locale.begin(),
static_cast<char (*)(char)>(&base::ToUpperASCII));
[](char c) { return base::ToUpperASCII(c); });

if (!locale_constraint.empty())
locale += locale_constraint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ class MediaNotificationViewModernImplTest : public views::ViewsTestBase {
std::vector<views::Button*> media_control_buttons() const {
std::vector<views::Button*> buttons;
auto children = view()->media_controls_container_->children();
base::ranges::transform(children, std::back_inserter(buttons),
static_cast<views::Button* (*)(views::View*)>(
&views::Button::AsButton));
base::ranges::transform(
children, std::back_inserter(buttons),
[](auto* view) { return views::Button::AsButton(view); });
buttons.push_back(views::Button::AsButton(picture_in_picture_button()));
return buttons;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ float ScoredHistoryMatchTest::GetTopicalityScoreOfTermAgainstURLAndTitle(
String16Vector term_vector;
base::ranges::transform(
terms, std::back_inserter(term_vector),
static_cast<std::u16string (*)(base::StringPiece)>(&base::UTF8ToUTF16));
[](const auto& term) { return base::UTF8ToUTF16(term); });
std::string terms_joint =
std::accumulate(std::next(terms.begin()), terms.end(), terms[0],
[](std::string accumulator, std::string term) {
Expand Down
6 changes: 3 additions & 3 deletions components/spellcheck/renderer/spellcheck.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ bool UpdateSpellcheckEnabled::Visit(content::RenderFrame* render_frame) {
WebVector<WebString> ConvertToWebStringFromUtf8(
const std::set<std::string>& words) {
WebVector<WebString> result(words.size());
base::ranges::transform(
words, result.begin(),
static_cast<WebString (*)(const std::string&)>(&WebString::FromUTF8));
base::ranges::transform(words, result.begin(), [](const auto& word) {
return WebString::FromUTF8(word);
});
return result;
}

Expand Down
5 changes: 3 additions & 2 deletions components/spellcheck/renderer/spellcheck_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,9 @@ void SpellCheckProvider::CheckSpelling(
spellcheck::FillSuggestions(per_language_suggestions, &suggestions);
WebVector<WebString> web_suggestions(suggestions.size());
base::ranges::transform(suggestions, web_suggestions.begin(),
static_cast<WebString (*)(const std::u16string&)>(
&WebString::FromUTF16));
[](const auto& suggestion) {
return WebString::FromUTF16(suggestion);
});
*optional_suggestions = web_suggestions;
spellcheck_renderer_metrics::RecordCheckedTextLengthWithSuggestions(
base::saturated_cast<int>(word.size()));
Expand Down
7 changes: 3 additions & 4 deletions content/renderer/render_frame_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3283,10 +3283,9 @@ RenderFrameImpl::CreateWorkerFetchContext() {
RenderThreadImpl::current()->cors_exempt_header_list();
blink::WebVector<blink::WebString> web_cors_exempt_header_list(
cors_exempt_header_list.size());
base::ranges::transform(cors_exempt_header_list,
web_cors_exempt_header_list.begin(),
static_cast<blink::WebString (*)(const std::string&)>(
&blink::WebString::FromLatin1));
base::ranges::transform(
cors_exempt_header_list, web_cors_exempt_header_list.begin(),
[](const auto& header) { return blink::WebString::FromLatin1(header); });

// |pending_subresource_loader_updater| and
// |pending_resource_load_info_notifier| are not used for
Expand Down
7 changes: 3 additions & 4 deletions content/renderer/render_thread_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -938,10 +938,9 @@ void RenderThreadImpl::InitializeRenderer(

blink::WebVector<blink::WebString> web_cors_exempt_header_list(
cors_exempt_header_list.size());
base::ranges::transform(cors_exempt_header_list,
web_cors_exempt_header_list.begin(),
static_cast<blink::WebString (*)(const std::string&)>(
&blink::WebString::FromLatin1));
base::ranges::transform(
cors_exempt_header_list, web_cors_exempt_header_list.begin(),
[](const auto& header) { return blink::WebString::FromLatin1(header); });
blink::SetCorsExemptHeaderList(web_cors_exempt_header_list);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,9 @@ ServiceWorkerContextClient::CreateWorkerFetchContextOnInitiatorThread() {

blink::WebVector<blink::WebString> web_cors_exempt_header_list(
cors_exempt_header_list_.size());
base::ranges::transform(cors_exempt_header_list_,
web_cors_exempt_header_list.begin(),
static_cast<blink::WebString (*)(const std::string&)>(
&blink::WebString::FromLatin1));
base::ranges::transform(
cors_exempt_header_list_, web_cors_exempt_header_list.begin(),
[](const auto& header) { return blink::WebString::FromLatin1(header); });

return blink::WebServiceWorkerFetchContext::Create(
renderer_preferences_, script_url_, loader_factories_->PassInterface(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,9 @@ DedicatedWorkerHostFactoryClient::CreateWorkerFetchContext(
RenderThreadImpl::current()->cors_exempt_header_list();
blink::WebVector<blink::WebString> web_cors_exempt_header_list(
cors_exempt_header_list.size());
base::ranges::transform(cors_exempt_header_list,
web_cors_exempt_header_list.begin(),
static_cast<blink::WebString (*)(const std::string&)>(
&blink::WebString::FromLatin1));
base::ranges::transform(
cors_exempt_header_list, web_cors_exempt_header_list.begin(),
[](const auto& header) { return blink::WebString::FromLatin1(header); });
scoped_refptr<blink::WebDedicatedOrSharedWorkerFetchContext>
web_dedicated_or_shared_worker_fetch_context =
blink::WebDedicatedOrSharedWorkerFetchContext::Create(
Expand Down
7 changes: 3 additions & 4 deletions content/renderer/worker/embedded_shared_worker_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,9 @@ EmbeddedSharedWorkerStub::CreateWorkerFetchContext(

blink::WebVector<blink::WebString> web_cors_exempt_header_list(
cors_exempt_header_list.size());
base::ranges::transform(cors_exempt_header_list,
web_cors_exempt_header_list.begin(),
static_cast<blink::WebString (*)(const std::string&)>(
&blink::WebString::FromLatin1));
base::ranges::transform(
cors_exempt_header_list, web_cors_exempt_header_list.begin(),
[](const auto& header) { return blink::WebString::FromLatin1(header); });

// |pending_subresource_loader_updater| and
// |pending_resource_load_info_notifier| are not used for shared workers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,11 @@ WebURLResponse WebURLResponse::Create(

WebVector<WebString> cors_exposed_header_names(
head.cors_exposed_header_names.size());
base::ranges::transform(
head.cors_exposed_header_names, cors_exposed_header_names.begin(),
static_cast<WebString (*)(const std::string&)>(&WebString::FromLatin1));
base::ranges::transform(head.cors_exposed_header_names,
cors_exposed_header_names.begin(),
[](const auto& header_name) {
return WebString::FromLatin1(header_name);
});
response.SetCorsExposedHeaderNames(cors_exposed_header_names);
response.SetDidServiceWorkerNavigationPreload(
head.did_service_worker_navigation_preload);
Expand Down

0 comments on commit 2f1b3da

Please sign in to comment.