Skip to content

Commit

Permalink
Expanded the performance lints (flutter#47868)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke authored Nov 9, 2023
1 parent d4a51fa commit e80af85
Show file tree
Hide file tree
Showing 29 changed files with 37 additions and 25 deletions.
4 changes: 4 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ Checks: >-
-clang-analyzer-nullability.NullablePassedToNonnull,
-clang-analyzer-nullability.NullReturnedFromNonnull,
-clang-analyzer-nullability.NullableReturnedFromNonnull,
performance-for-range-copy,
performance-inefficient-vector-operation,
performance-move-const-arg,
performance-move-constructor-init,
performance-unnecessary-copy-initialization,
performance-unnecessary-value-param
CheckOptions:
Expand Down
2 changes: 1 addition & 1 deletion display_list/geometry/dl_rtree_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ TEST(DisplayListRTree, Region) {
rect[i] = SkRect::MakeXYWH(i * 10, i * 10, 20, 20);
}
DlRTree rtree(rect, 9);
auto region = rtree.region();
const auto& region = rtree.region();
auto rects = region.getRects(true);
std::vector<SkIRect> expected_rects{
SkIRect::MakeLTRB(0, 0, 20, 10), SkIRect::MakeLTRB(0, 10, 30, 20),
Expand Down
2 changes: 1 addition & 1 deletion display_list/testing/dl_rendering_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2829,7 +2829,7 @@ class DisplayListRenderingTestBase : public BaseT,
FML_LOG(INFO) << CanvasCompareTester::ImpellerFailureImages.size()
<< " images saved in "
<< CanvasCompareTester::ImpellerFailureImageDirectory;
for (auto filename : CanvasCompareTester::ImpellerFailureImages) {
for (const auto& filename : CanvasCompareTester::ImpellerFailureImages) {
FML_LOG(INFO) << " " << filename;
}
FML_LOG(INFO);
Expand Down
2 changes: 2 additions & 0 deletions fml/memory/ref_counted_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ TEST(RefCountedTest, Constructors) {
was_destroyed = false;
RefPtr<MyClass> r1(MakeRefCounted<MyClass>(&created, &was_destroyed));
// Copy.
// NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
RefPtr<MyClass> r2(r1);
EXPECT_TRUE(created);
EXPECT_EQ(created, r1.get());
Expand Down Expand Up @@ -543,6 +544,7 @@ TEST(RefCountedTest, Mix) {
RefPtr<MyClass> r3 = r2;
EXPECT_FALSE(created->HasOneRef());
{
// NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
RefPtr<MyClass> r4(r3);
r2 = nullptr;
ASSERT_FALSE(was_destroyed);
Expand Down
2 changes: 1 addition & 1 deletion fml/memory/weak_ptr_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ TEST(WeakPtrTest, CopyConstruction) {
int data = 0;
WeakPtrFactory<int> factory(&data);
WeakPtr<int> ptr = factory.GetWeakPtr();
WeakPtr<int> ptr2(ptr);
const WeakPtr<int>& ptr2(ptr);
EXPECT_EQ(&data, ptr.get());
EXPECT_EQ(&data, ptr2.get());
}
Expand Down
4 changes: 2 additions & 2 deletions fml/message_loop_task_queues_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ static void BM_RegisterAndGetTasks(benchmark::State& state) { // NOLINT
CountDownLatch tasks_registered(num_task_queues);
CountDownLatch tasks_done(num_task_queues);

threads.reserve(num_task_queues);
for (int i = 0; i < num_task_queues; i++) {
threads.emplace_back([task_runner_id = i, &task_queue, past, &tasks_done,
&tasks_registered]() {
for (int j = 0; j < num_tasks_per_queue; j++) {
task_queue->RegisterTask(
TaskQueueId(task_runner_id), [] {}, past);
task_queue->RegisterTask(TaskQueueId(task_runner_id), [] {}, past);
}
tasks_registered.CountDown();
tasks_registered.Wait();
Expand Down
2 changes: 1 addition & 1 deletion impeller/aiks/paint_pass_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ bool OpacityPeepholePassDelegate::CanCollapseIntoParentPass(
std::vector<Rect> all_coverages;
auto had_subpass = entity_pass->IterateUntilSubpass(
[&all_coverages, &all_can_accept](Entity& entity) {
auto contents = entity.GetContents();
const auto& contents = entity.GetContents();
if (!entity.CanInheritOpacity()) {
all_can_accept = false;
return false;
Expand Down
2 changes: 1 addition & 1 deletion impeller/compiler/uniform_sorter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ std::vector<spirv_cross::ID> SortUniforms(
if (var.storage != spv::StorageClassUniformConstant) {
return;
}
const auto type = compiler->get_type(var.basetype);
const auto& type = compiler->get_type(var.basetype);
if (!type_filter.has_value() ||
(include && type_filter.value() == type.basetype) ||
(!include && type_filter.value() != type.basetype)) {
Expand Down
2 changes: 1 addition & 1 deletion impeller/display_list/dl_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ TEST_P(DisplayListTest, MaskBlursApplyCorrectlyToColorSources) {
stops.data(), flutter::DlTileMode::kClamp)};

int offset = 100;
for (auto color_source : color_sources) {
for (const auto& color_source : color_sources) {
flutter::DlPaint paint;
paint.setColorSource(color_source);
paint.setMaskFilter(blur_filter);
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/filters/filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ std::optional<Rect> FilterContents::GetSourceCoverage(
}

std::optional<Rect> inputs_coverage;
for (auto input : inputs_) {
for (const auto& input : inputs_) {
auto input_coverage = input->GetSourceCoverage(
effect_transform, filter_input_coverage.value());
if (!input_coverage.has_value()) {
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/runtime_effect_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
size_t minimum_sampler_index = 100000000;
size_t buffer_index = 0;
size_t buffer_offset = 0;
for (auto uniform : runtime_stage_->GetUniforms()) {
for (const auto& uniform : runtime_stage_->GetUniforms()) {
// TODO(113715): Populate this metadata once GLES is able to handle
// non-struct uniform names.
std::shared_ptr<ShaderMetadata> metadata =
Expand Down Expand Up @@ -225,7 +225,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
}

size_t sampler_index = 0;
for (auto uniform : runtime_stage_->GetUniforms()) {
for (const auto& uniform : runtime_stage_->GetUniforms()) {
// TODO(113715): Populate this metadata once GLES is able to handle
// non-struct uniform names.
ShaderMetadata metadata;
Expand Down
1 change: 1 addition & 0 deletions impeller/entity/contents/vertices_contents_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ std::shared_ptr<VerticesGeometry> CreateColorVertices(
const std::vector<Color>& colors) {
auto bounds = Rect::MakePointBounds(vertices.begin(), vertices.end());
std::vector<uint16_t> indices = {};
indices.reserve(vertices.size());
for (auto i = 0u; i < vertices.size(); i++) {
indices.emplace_back(i);
}
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/entity_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ bool EntityPass::Render(ContentContext& renderer,

IterateAllEntities([lazy_glyph_atlas =
renderer.GetLazyGlyphAtlas()](const Entity& entity) {
if (auto contents = entity.GetContents()) {
if (const auto& contents = entity.GetContents()) {
contents->PopulateGlyphAtlas(lazy_glyph_atlas, entity.DeriveTextScale());
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/gles/buffer_bindings_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ const std::vector<GLint>& BufferBindingsGLES::ComputeUniformLocations(
// For each metadata member, look up the binding location and record
// it in the binding map.
auto& locations = binding_map_[metadata->name] = {};
for (const auto member : metadata->members) {
for (const auto& member : metadata->members) {
if (member.type == ShaderType::kVoid) {
// Void types are used for padding. We are obviously not going to find
// mappings for these. Keep going.
Expand Down
3 changes: 2 additions & 1 deletion impeller/renderer/pool_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ TEST(PoolTest, Overload) {
Pool<Foobar> pool(1'000);
{
std::vector<std::shared_ptr<Foobar>> values;
values.reserve(20);
for (int i = 0; i < 20; i++) {
values.push_back(pool.Grab());
}
for (auto value : values) {
for (const auto& value : values) {
value->SetSize(100);
pool.Recycle(value);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/painting/fragment_program.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ std::string FragmentProgram::initFromAsset(const std::string& asset_name) {
runtime_effect_ = DlRuntimeEffect::MakeImpeller(
std::make_unique<impeller::RuntimeStage>(std::move(runtime_stage)));
} else {
auto code_mapping = runtime_stage.GetSkSLMapping();
const auto& code_mapping = runtime_stage.GetSkSLMapping();
auto code_size = code_mapping->GetSize();
const char* sksl =
reinterpret_cast<const char*>(code_mapping->GetMapping());
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/painting/path_measure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void CanvasPathMeasure::Create(Dart_Handle wrapper,
fml::RefPtr<CanvasPathMeasure> pathMeasure =
fml::MakeRefCounted<CanvasPathMeasure>();
if (path) {
const SkPath skPath = path->path();
const SkPath& skPath = path->path();
SkScalar resScale = 1;
pathMeasure->path_measure_ =
std::make_unique<SkContourMeasureIter>(skPath, forceClosed, resScale);
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/ui_benchmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static void BM_PathVolatilityTracker(benchmark::State& state) {

fml::AutoResetWaitableEvent latch;
task_runners.GetUITaskRunner()->PostTask([&]() {
for (auto path : paths) {
for (const auto& path : paths) {
tracker.Track(path);
}
latch.Signal();
Expand Down
1 change: 1 addition & 0 deletions runtime/dart_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ bool DartIsolate::LoadKernel(const std::shared_ptr<const fml::Mapping>& mapping,
[[nodiscard]] bool DartIsolate::PrepareForRunningFromKernels(
std::vector<std::unique_ptr<const fml::Mapping>> kernels) {
std::vector<std::shared_ptr<const fml::Mapping>> shared_kernels;
shared_kernels.reserve(kernels.size());
for (auto& kernel : kernels) {
shared_kernels.emplace_back(std::move(kernel));
}
Expand Down
1 change: 1 addition & 0 deletions runtime/service_protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ bool ServiceProtocol::HandleListViewsMethod(
rapidjson::Document* response) const {
fml::SharedLock lock(*handlers_mutex_);
std::vector<std::pair<intptr_t, Handler::Description>> descriptions;
descriptions.reserve(handlers_.size());
for (const auto& handler : handlers_) {
descriptions.emplace_back(reinterpret_cast<intptr_t>(handler.first),
handler.second.Load());
Expand Down
2 changes: 1 addition & 1 deletion shell/common/resource_cache_limit_calculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ size_t ResourceCacheLimitCalculator::GetResourceCacheMaxBytes() {
? max_bytes_threshold_
: std::numeric_limits<size_t>::max();
std::vector<fml::WeakPtr<ResourceCacheLimitItem>> live_items;
for (auto item : items_) {
for (const auto& item : items_) {
if (item) {
live_items.push_back(item);
max_bytes += item->GetResourceCacheLimit();
Expand Down
2 changes: 1 addition & 1 deletion shell/common/serialization_callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct ImageMetaData {
} __attribute__((packed));

sk_sp<SkData> SerializeImageWithoutData(SkImage* image, void* ctx) {
auto info = image->imageInfo();
const auto& info = image->imageInfo();
SkDynamicMemoryWStream stream;

ImageMetaData metadata = {info.width(), info.height(),
Expand Down
1 change: 1 addition & 0 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2219,6 +2219,7 @@ void Shell::OnDisplayUpdates(std::vector<std::unique_ptr<Display>> displays) {
FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread());

std::vector<DisplayData> display_data;
display_data.reserve(displays.size());
for (const auto& display : displays) {
display_data.push_back(display->GetDisplayData());
}
Expand Down
2 changes: 1 addition & 1 deletion shell/common/shell_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3162,7 +3162,7 @@ TEST_F(ShellTest, AssetManagerMulti) {
"bad1",
};

for (auto filename : filenames) {
for (const auto& filename : filenames) {
bool success = fml::WriteAtomically(asset_dir_fd, filename.c_str(),
fml::DataMapping(filename));
ASSERT_TRUE(success);
Expand Down
2 changes: 1 addition & 1 deletion shell/common/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
&all_dart_flags)) {
// Assume that individual flags are comma separated.
std::vector<std::string> flags = ParseCommaDelimited(all_dart_flags);
for (auto flag : flags) {
for (const auto& flag : flags) {
if (!IsAllowedDartVMFlag(flag)) {
FML_LOG(FATAL) << "Encountered disallowed Dart VM flag: " << flag;
}
Expand Down
4 changes: 2 additions & 2 deletions shell/platform/common/accessibility_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void AccessibilityBridge::CommitUpdates() {
}

for (size_t i = results.size(); i > 0; i--) {
for (SemanticsNode node : results[i - 1]) {
for (const SemanticsNode& node : results[i - 1]) {
ConvertFlutterUpdate(node, update);
}
}
Expand Down Expand Up @@ -203,7 +203,7 @@ std::optional<ui::AXTreeUpdate>
AccessibilityBridge::CreateRemoveReparentedNodesUpdate() {
std::unordered_map<int32_t, ui::AXNodeData> updates;

for (auto node_update : pending_semantics_node_updates_) {
for (const auto& node_update : pending_semantics_node_updates_) {
for (int32_t child_id : node_update.second.children_in_traversal_order) {
// Skip nodes that don't exist or have a parent in the current tree.
ui::AXNode* child = tree_->GetFromId(child_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
ui::AXNode* ax_node = targeted_event.node;
std::vector<AccessibilityBridgeMac::NSAccessibilityEvent> events =
MacOSEventsFromAXEvent(targeted_event.event_params.event, *ax_node);
for (AccessibilityBridgeMac::NSAccessibilityEvent event : events) {
for (const AccessibilityBridgeMac::NSAccessibilityEvent& event : events) {
if (event.user_info != nil) {
DispatchMacOSNotificationWithUserInfo(event.target, event.name, event.user_info);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void ApplyFlutterLayer(FlutterMutatorView* view,
flutterPlatformView.identifier = 0;

std::vector<const FlutterPlatformViewMutation*> mutationPointers;
mutationPointers.reserve(mutations.size());
for (auto& mutation : mutations) {
mutationPointers.push_back(&mutation);
}
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/embedder/tests/embedder_test_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ VoidCallback EmbedderTestContext::GetIsolateCreateCallbackHook() {
}

void EmbedderTestContext::FireIsolateCreateCallbacks() {
for (auto closure : isolate_create_callbacks_) {
for (const auto& closure : isolate_create_callbacks_) {
closure();
}
}
Expand Down

0 comments on commit e80af85

Please sign in to comment.