Make a variety of low-impact Clang tidy fixes. (flutter/engine#46114)
Work towards https://github.com/flutter/flutter/issues/134969. These are all self-contained, so I bundled them all together. All fixes are generated by `clang-tidy --fix`, and manual search/replace if that wasn't sufficient.
This commit is contained in:
@@ -14,7 +14,7 @@ Texture::Texture(int64_t id) : id_(id) {}
|
||||
|
||||
Texture::~Texture() = default;
|
||||
|
||||
TextureRegistry::TextureRegistry() : image_counter_(0) {}
|
||||
TextureRegistry::TextureRegistry() = default;
|
||||
|
||||
void TextureRegistry::RegisterTexture(const std::shared_ptr<Texture>& texture) {
|
||||
if (!texture) {
|
||||
|
||||
@@ -95,7 +95,7 @@ class TextureRegistry {
|
||||
|
||||
private:
|
||||
std::map<int64_t, std::shared_ptr<Texture>> mapping_;
|
||||
size_t image_counter_;
|
||||
size_t image_counter_ = 0;
|
||||
// This map keeps track of registered context listeners by their own
|
||||
// externally provided id. It indexes into ordered_images_.
|
||||
std::map<uintptr_t, size_t> image_indices_;
|
||||
|
||||
@@ -159,7 +159,8 @@ class SaveLayerOptions {
|
||||
|
||||
SaveLayerOptions() : flags_(0) {}
|
||||
SaveLayerOptions(const SaveLayerOptions& options) : flags_(options.flags_) {}
|
||||
SaveLayerOptions(const SaveLayerOptions* options) : flags_(options->flags_) {}
|
||||
explicit SaveLayerOptions(const SaveLayerOptions* options)
|
||||
: flags_(options->flags_) {}
|
||||
|
||||
SaveLayerOptions without_optimizations() const {
|
||||
SaveLayerOptions options;
|
||||
|
||||
@@ -152,7 +152,7 @@ class DlCanvas {
|
||||
virtual void DrawVertices(const DlVertices* vertices,
|
||||
DlBlendMode mode,
|
||||
const DlPaint& paint) = 0;
|
||||
void DrawVertices(const std::shared_ptr<const DlVertices> vertices,
|
||||
void DrawVertices(const std::shared_ptr<const DlVertices>& vertices,
|
||||
DlBlendMode mode,
|
||||
const DlPaint& paint) {
|
||||
DrawVertices(vertices.get(), mode, paint);
|
||||
|
||||
@@ -217,7 +217,7 @@ const SkRect& DlRTree::bounds() const {
|
||||
if (!nodes_.empty()) {
|
||||
return nodes_.back().bounds;
|
||||
} else {
|
||||
return empty_;
|
||||
return kEmpty;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ class DlRTree : public SkRefCnt {
|
||||
const SkRect& bounds(int result_index) const {
|
||||
return (result_index >= 0 && result_index < leaf_count_)
|
||||
? nodes_[result_index].bounds
|
||||
: empty_;
|
||||
: kEmpty;
|
||||
}
|
||||
|
||||
/// Returns the bytes used by the object and all of its node data.
|
||||
@@ -136,7 +136,7 @@ class DlRTree : public SkRefCnt {
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr SkRect empty_ = SkRect::MakeEmpty();
|
||||
static constexpr SkRect kEmpty = SkRect::MakeEmpty();
|
||||
|
||||
void search(const Node& parent,
|
||||
const SkRect& query,
|
||||
|
||||
@@ -131,7 +131,9 @@ class DlImage : public SkRefCnt {
|
||||
|
||||
bool Equals(const DlImage& other) const { return Equals(&other); }
|
||||
|
||||
bool Equals(sk_sp<const DlImage> other) const { return Equals(other.get()); }
|
||||
bool Equals(const sk_sp<const DlImage>& other) const {
|
||||
return Equals(other.get());
|
||||
}
|
||||
|
||||
protected:
|
||||
DlImage();
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace flutter {
|
||||
|
||||
class DlImageSkia final : public DlImage {
|
||||
public:
|
||||
DlImageSkia(sk_sp<SkImage> image);
|
||||
explicit DlImageSkia(sk_sp<SkImage> image);
|
||||
|
||||
// |DlImage|
|
||||
~DlImageSkia() override;
|
||||
|
||||
@@ -25,7 +25,7 @@ class BitConverter {
|
||||
int Extract() {
|
||||
FML_DCHECK(CanExtract());
|
||||
int result = Peek();
|
||||
buffer_ = (buffer_ << to_length) & mask_;
|
||||
buffer_ = (buffer_ << to_length) & kMask;
|
||||
lower_free_bits_ += to_length;
|
||||
return result;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ class BitConverter {
|
||||
static_assert(buffer_length >= 2 * to_length);
|
||||
static_assert(buffer_length < sizeof(int) * 8);
|
||||
|
||||
static constexpr int mask_ = (1 << buffer_length) - 1;
|
||||
static constexpr int kMask = (1 << buffer_length) - 1;
|
||||
|
||||
int buffer_ = 0;
|
||||
int lower_free_bits_ = buffer_length;
|
||||
|
||||
@@ -32,11 +32,11 @@ struct IsByteSwappable
|
||||
integral_constant<bool, std::is_integral_v<T> || std::is_enum_v<T>> {
|
||||
};
|
||||
template <typename T>
|
||||
constexpr bool IsByteSwappableV = IsByteSwappable<T>::value;
|
||||
constexpr bool kIsByteSwappableV = IsByteSwappable<T>::value;
|
||||
|
||||
/// @brief Flips the endianness of the given value.
|
||||
/// The given value must be an integral type of size 1, 2, 4, or 8.
|
||||
template <typename T, class = std::enable_if_t<IsByteSwappableV<T>>>
|
||||
template <typename T, class = std::enable_if_t<kIsByteSwappableV<T>>>
|
||||
constexpr T ByteSwap(T n) {
|
||||
if constexpr (sizeof(T) == 1) {
|
||||
return n;
|
||||
@@ -55,7 +55,7 @@ constexpr T ByteSwap(T n) {
|
||||
/// current architecture. This is effectively a cross platform
|
||||
/// ntohl/ntohs (as network byte order is always Big Endian).
|
||||
/// The given value must be an integral type of size 1, 2, 4, or 8.
|
||||
template <typename T, class = std::enable_if_t<IsByteSwappableV<T>>>
|
||||
template <typename T, class = std::enable_if_t<kIsByteSwappableV<T>>>
|
||||
constexpr T BigEndianToArch(T n) {
|
||||
#if FML_ARCH_CPU_LITTLE_ENDIAN
|
||||
return ByteSwap<T>(n);
|
||||
@@ -67,7 +67,7 @@ constexpr T BigEndianToArch(T n) {
|
||||
/// @brief Convert a known little endian value to match the endianness of the
|
||||
/// current architecture.
|
||||
/// The given value must be an integral type of size 1, 2, 4, or 8.
|
||||
template <typename T, class = std::enable_if_t<IsByteSwappableV<T>>>
|
||||
template <typename T, class = std::enable_if_t<kIsByteSwappableV<T>>>
|
||||
constexpr T LittleEndianToArch(T n) {
|
||||
#if !FML_ARCH_CPU_LITTLE_ENDIAN
|
||||
return ByteSwap<T>(n);
|
||||
|
||||
@@ -12,16 +12,16 @@ namespace math {
|
||||
constexpr float kE = 2.7182818284590452354;
|
||||
|
||||
// log_2 e
|
||||
constexpr float kLog2_E = 1.4426950408889634074;
|
||||
constexpr float kLog2E = 1.4426950408889634074;
|
||||
|
||||
// log_10 e
|
||||
constexpr float kLog10_E = 0.43429448190325182765;
|
||||
constexpr float kLog10E = 0.43429448190325182765;
|
||||
|
||||
// log_e 2
|
||||
constexpr float klogE_2 = 0.69314718055994530942;
|
||||
constexpr float kLogE2 = 0.69314718055994530942;
|
||||
|
||||
// log_e 10
|
||||
constexpr float klogE_10 = 2.30258509299404568402;
|
||||
constexpr float kLogE10 = 2.30258509299404568402;
|
||||
|
||||
// pi
|
||||
constexpr float kPi = 3.14159265358979323846;
|
||||
|
||||
@@ -12,9 +12,9 @@ namespace testing {
|
||||
|
||||
TEST(MathTest, Constants) {
|
||||
// Don't use the constants in cmath as those aren't portable.
|
||||
EXPECT_FLOAT_EQ(std::log2(math::kE), math::kLog2_E);
|
||||
EXPECT_FLOAT_EQ(std::log10(math::kE), math::kLog10_E);
|
||||
EXPECT_FLOAT_EQ(std::log(2.0f), math::klogE_2);
|
||||
EXPECT_FLOAT_EQ(std::log2(math::kE), math::kLog2E);
|
||||
EXPECT_FLOAT_EQ(std::log10(math::kE), math::kLog10E);
|
||||
EXPECT_FLOAT_EQ(std::log(2.0f), math::kLogE2);
|
||||
EXPECT_FLOAT_EQ(math::kPi / 2.0f, math::kPiOver2);
|
||||
EXPECT_FLOAT_EQ(math::kPi / 4.0f, math::kPiOver4);
|
||||
EXPECT_FLOAT_EQ(1.0f / math::kPi, math::k1OverPi);
|
||||
|
||||
@@ -205,7 +205,7 @@ class RefPtr final {
|
||||
|
||||
friend RefPtr<T> AdoptRef<T>(T*);
|
||||
|
||||
enum AdoptTag { ADOPT };
|
||||
enum AdoptTag { kAdopt };
|
||||
RefPtr(T* ptr, AdoptTag) : ptr_(ptr) { FML_DCHECK(ptr_); }
|
||||
|
||||
T* ptr_;
|
||||
@@ -222,7 +222,7 @@ inline RefPtr<T> AdoptRef(T* ptr) {
|
||||
#ifndef NDEBUG
|
||||
ptr->Adopt();
|
||||
#endif
|
||||
return RefPtr<T>(ptr, RefPtr<T>::ADOPT);
|
||||
return RefPtr<T>(ptr, RefPtr<T>::kAdopt);
|
||||
}
|
||||
|
||||
// Constructs a |RefPtr<T>| from a plain pointer (to an object that must
|
||||
|
||||
@@ -36,7 +36,7 @@ FML_THREAD_LOCAL ThreadLocalUniquePtr<TaskSourceGradeHolder>
|
||||
tls_task_source_grade;
|
||||
|
||||
TaskQueueEntry::TaskQueueEntry(TaskQueueId created_for_arg)
|
||||
: subsumed_by(_kUnmerged), created_for(created_for_arg) {
|
||||
: subsumed_by(kUnmerged), created_for(created_for_arg) {
|
||||
wakeable = NULL;
|
||||
task_observers = TaskObservers();
|
||||
task_source = std::make_unique<TaskSource>(created_for);
|
||||
@@ -66,7 +66,7 @@ MessageLoopTaskQueues::~MessageLoopTaskQueues() = default;
|
||||
void MessageLoopTaskQueues::Dispose(TaskQueueId queue_id) {
|
||||
std::lock_guard guard(queue_mutex_);
|
||||
const auto& queue_entry = queue_entries_.at(queue_id);
|
||||
FML_DCHECK(queue_entry->subsumed_by == _kUnmerged);
|
||||
FML_DCHECK(queue_entry->subsumed_by == kUnmerged);
|
||||
auto& subsumed_set = queue_entry->owner_of;
|
||||
for (auto& subsumed : subsumed_set) {
|
||||
queue_entries_.erase(subsumed);
|
||||
@@ -78,7 +78,7 @@ void MessageLoopTaskQueues::Dispose(TaskQueueId queue_id) {
|
||||
void MessageLoopTaskQueues::DisposeTasks(TaskQueueId queue_id) {
|
||||
std::lock_guard guard(queue_mutex_);
|
||||
const auto& queue_entry = queue_entries_.at(queue_id);
|
||||
FML_DCHECK(queue_entry->subsumed_by == _kUnmerged);
|
||||
FML_DCHECK(queue_entry->subsumed_by == kUnmerged);
|
||||
auto& subsumed_set = queue_entry->owner_of;
|
||||
queue_entry->task_source->ShutDown();
|
||||
for (auto& subsumed : subsumed_set) {
|
||||
@@ -101,7 +101,7 @@ void MessageLoopTaskQueues::RegisterTask(
|
||||
queue_entry->task_source->RegisterTask(
|
||||
{order, task, target_time, task_source_grade});
|
||||
TaskQueueId loop_to_wake = queue_id;
|
||||
if (queue_entry->subsumed_by != _kUnmerged) {
|
||||
if (queue_entry->subsumed_by != kUnmerged) {
|
||||
loop_to_wake = queue_entry->subsumed_by;
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ void MessageLoopTaskQueues::WakeUpUnlocked(TaskQueueId queue_id,
|
||||
size_t MessageLoopTaskQueues::GetNumPendingTasks(TaskQueueId queue_id) const {
|
||||
std::lock_guard guard(queue_mutex_);
|
||||
const auto& queue_entry = queue_entries_.at(queue_id);
|
||||
if (queue_entry->subsumed_by != _kUnmerged) {
|
||||
if (queue_entry->subsumed_by != kUnmerged) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ std::vector<fml::closure> MessageLoopTaskQueues::GetObserversToNotify(
|
||||
std::lock_guard guard(queue_mutex_);
|
||||
std::vector<fml::closure> observers;
|
||||
|
||||
if (queue_entries_.at(queue_id)->subsumed_by != _kUnmerged) {
|
||||
if (queue_entries_.at(queue_id)->subsumed_by != kUnmerged) {
|
||||
return observers;
|
||||
}
|
||||
|
||||
@@ -226,8 +226,8 @@ bool MessageLoopTaskQueues::Merge(TaskQueueId owner, TaskQueueId subsumed) {
|
||||
// Won't check owner_entry->owner_of, because it may contains items when
|
||||
// merged with other different queues.
|
||||
|
||||
// Ensure owner_entry->subsumed_by being _kUnmerged
|
||||
if (owner_entry->subsumed_by != _kUnmerged) {
|
||||
// Ensure owner_entry->subsumed_by being kUnmerged
|
||||
if (owner_entry->subsumed_by != kUnmerged) {
|
||||
FML_LOG(WARNING) << "Thread merging failed: owner_entry was already "
|
||||
"subsumed by others, owner="
|
||||
<< owner << ", subsumed=" << subsumed
|
||||
@@ -242,8 +242,8 @@ bool MessageLoopTaskQueues::Merge(TaskQueueId owner, TaskQueueId subsumed) {
|
||||
<< ", subsumed->owner_of.size()=" << subsumed_entry->owner_of.size();
|
||||
return false;
|
||||
}
|
||||
// Ensure subsumed_entry->subsumed_by being _kUnmerged
|
||||
if (subsumed_entry->subsumed_by != _kUnmerged) {
|
||||
// Ensure subsumed_entry->subsumed_by being kUnmerged
|
||||
if (subsumed_entry->subsumed_by != kUnmerged) {
|
||||
FML_LOG(WARNING) << "Thread merging failed: subsumed_entry was already "
|
||||
"subsumed by others, owner="
|
||||
<< owner << ", subsumed=" << subsumed
|
||||
@@ -271,14 +271,14 @@ bool MessageLoopTaskQueues::Unmerge(TaskQueueId owner, TaskQueueId subsumed) {
|
||||
<< owner << ", subsumed=" << subsumed;
|
||||
return false;
|
||||
}
|
||||
if (owner_entry->subsumed_by != _kUnmerged) {
|
||||
if (owner_entry->subsumed_by != kUnmerged) {
|
||||
FML_LOG(WARNING)
|
||||
<< "Thread unmerging failed: owner_entry was subsumed by others, owner="
|
||||
<< owner << ", subsumed=" << subsumed
|
||||
<< ", owner_entry->subsumed_by=" << owner_entry->subsumed_by;
|
||||
return false;
|
||||
}
|
||||
if (queue_entries_.at(subsumed)->subsumed_by == _kUnmerged) {
|
||||
if (queue_entries_.at(subsumed)->subsumed_by == kUnmerged) {
|
||||
FML_LOG(WARNING) << "Thread unmerging failed: subsumed_entry wasn't "
|
||||
"subsumed by others, owner="
|
||||
<< owner << ", subsumed=" << subsumed;
|
||||
@@ -291,7 +291,7 @@ bool MessageLoopTaskQueues::Unmerge(TaskQueueId owner, TaskQueueId subsumed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
queue_entries_.at(subsumed)->subsumed_by = _kUnmerged;
|
||||
queue_entries_.at(subsumed)->subsumed_by = kUnmerged;
|
||||
owner_entry->owner_of.erase(subsumed);
|
||||
|
||||
if (HasPendingTasksUnlocked(owner)) {
|
||||
@@ -308,7 +308,7 @@ bool MessageLoopTaskQueues::Unmerge(TaskQueueId owner, TaskQueueId subsumed) {
|
||||
bool MessageLoopTaskQueues::Owns(TaskQueueId owner,
|
||||
TaskQueueId subsumed) const {
|
||||
std::lock_guard guard(queue_mutex_);
|
||||
if (owner == _kUnmerged || subsumed == _kUnmerged) {
|
||||
if (owner == kUnmerged || subsumed == kUnmerged) {
|
||||
return false;
|
||||
}
|
||||
auto& subsumed_set = queue_entries_.at(owner)->owner_of;
|
||||
@@ -340,7 +340,7 @@ void MessageLoopTaskQueues::ResumeSecondarySource(TaskQueueId queue_id) {
|
||||
bool MessageLoopTaskQueues::HasPendingTasksUnlocked(
|
||||
TaskQueueId queue_id) const {
|
||||
const auto& entry = queue_entries_.at(queue_id);
|
||||
bool is_subsumed = entry->subsumed_by != _kUnmerged;
|
||||
bool is_subsumed = entry->subsumed_by != kUnmerged;
|
||||
if (is_subsumed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
namespace fml {
|
||||
|
||||
static const TaskQueueId _kUnmerged = TaskQueueId(TaskQueueId::kUnmerged);
|
||||
static const TaskQueueId kUnmerged = TaskQueueId(TaskQueueId::kUnmerged);
|
||||
|
||||
/// A collection of tasks and observers associated with one TaskQueue.
|
||||
///
|
||||
@@ -40,7 +40,7 @@ class TaskQueueEntry {
|
||||
/// empty, this TaskQueue does not own any other TaskQueues.
|
||||
std::set<TaskQueueId> owner_of;
|
||||
|
||||
/// Identifies the TaskQueue that subsumes this TaskQueue. If it is _kUnmerged
|
||||
/// Identifies the TaskQueue that subsumes this TaskQueue. If it is kUnmerged
|
||||
/// it indicates that this TaskQueue is not owned by any other TaskQueue.
|
||||
TaskQueueId subsumed_by;
|
||||
|
||||
|
||||
@@ -338,9 +338,9 @@ TEST(MessageLoopTaskQueue, QueueDoNotOwnItself) {
|
||||
|
||||
TEST(MessageLoopTaskQueue, QueueDoNotOwnUnmergedTaskQueueId) {
|
||||
auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
|
||||
ASSERT_FALSE(task_queue->Owns(task_queue->CreateTaskQueue(), _kUnmerged));
|
||||
ASSERT_FALSE(task_queue->Owns(_kUnmerged, task_queue->CreateTaskQueue()));
|
||||
ASSERT_FALSE(task_queue->Owns(_kUnmerged, _kUnmerged));
|
||||
ASSERT_FALSE(task_queue->Owns(task_queue->CreateTaskQueue(), kUnmerged));
|
||||
ASSERT_FALSE(task_queue->Owns(kUnmerged, task_queue->CreateTaskQueue()));
|
||||
ASSERT_FALSE(task_queue->Owns(kUnmerged, kUnmerged));
|
||||
}
|
||||
|
||||
TEST(MessageLoopTaskQueue, QueueOwnsMergedTaskQueueId) {
|
||||
|
||||
@@ -17,20 +17,20 @@ namespace fml {
|
||||
enum class OwnershipPolicy {
|
||||
// The scoped object takes ownership of an object by taking over an existing
|
||||
// ownership claim.
|
||||
Assume,
|
||||
kAssume,
|
||||
|
||||
// The scoped object will retain the object and any initial ownership is
|
||||
// not changed.
|
||||
Retain,
|
||||
kRetain,
|
||||
};
|
||||
|
||||
template <typename B>
|
||||
class ScopedBlock {
|
||||
public:
|
||||
explicit ScopedBlock(B block = nullptr,
|
||||
OwnershipPolicy policy = OwnershipPolicy::Assume)
|
||||
OwnershipPolicy policy = OwnershipPolicy::kAssume)
|
||||
: block_(block) {
|
||||
if (block_ && policy == OwnershipPolicy::Retain) {
|
||||
if (block_ && policy == OwnershipPolicy::kRetain) {
|
||||
block_ = Block_copy(block);
|
||||
}
|
||||
}
|
||||
@@ -48,13 +48,13 @@ class ScopedBlock {
|
||||
}
|
||||
|
||||
ScopedBlock& operator=(const ScopedBlock<B>& that) {
|
||||
reset(that.get(), OwnershipPolicy::Retain);
|
||||
reset(that.get(), OwnershipPolicy::kRetain);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void reset(B block = nullptr,
|
||||
OwnershipPolicy policy = OwnershipPolicy::Assume) {
|
||||
if (block && policy == OwnershipPolicy::Retain) {
|
||||
OwnershipPolicy policy = OwnershipPolicy::kAssume) {
|
||||
if (block && policy == OwnershipPolicy::kRetain) {
|
||||
block = Block_copy(block);
|
||||
}
|
||||
if (block_) {
|
||||
|
||||
@@ -717,7 +717,7 @@ static void SendFakeTouchEvent(UIScreen* screen,
|
||||
}
|
||||
|
||||
- (void)setFlutterViewDidRenderCallback:(void (^)(void))callback {
|
||||
_flutterViewRenderedCallback.reset(callback, fml::OwnershipPolicy::Retain);
|
||||
_flutterViewRenderedCallback.reset(callback, fml::OwnershipPolicy::kRetain);
|
||||
}
|
||||
|
||||
#pragma mark - Surface creation and teardown updates
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace flutter {
|
||||
PlatformMessageResponseDarwin::PlatformMessageResponseDarwin(
|
||||
PlatformMessageResponseCallback callback,
|
||||
fml::RefPtr<fml::TaskRunner> platform_task_runner)
|
||||
: callback_(callback, fml::OwnershipPolicy::Retain),
|
||||
: callback_(callback, fml::OwnershipPolicy::kRetain),
|
||||
platform_task_runner_(std::move(platform_task_runner)) {}
|
||||
|
||||
PlatformMessageResponseDarwin::~PlatformMessageResponseDarwin() = default;
|
||||
|
||||
@@ -125,7 +125,7 @@ void PlatformMessageHandlerIos::SetMessageHandler(const std::string& channel,
|
||||
message_handlers_[channel] = {
|
||||
.task_queue = fml::scoped_nsprotocol([task_queue retain]),
|
||||
.handler =
|
||||
fml::ScopedBlock<FlutterBinaryMessageHandler>{handler, fml::OwnershipPolicy::Retain},
|
||||
fml::ScopedBlock<FlutterBinaryMessageHandler>{handler, fml::OwnershipPolicy::kRetain},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user