diff --git a/fml/ascii_trie.cc b/fml/ascii_trie.cc index e3cd521f054a6..4473cb571e3f8 100644 --- a/fml/ascii_trie.cc +++ b/fml/ascii_trie.cc @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT + #include "flutter/fml/ascii_trie.h" #include "flutter/fml/logging.h" @@ -38,7 +38,7 @@ bool AsciiTrie::Query(TrieNode* trie, const char* query) { FML_DCHECK(trie); const char* char_position = query; TrieNode* trie_position = trie; - TrieNode* child; + TrieNode* child = nullptr; int ch; while ((ch = *char_position) && (child = trie_position->children[ch].get())) { char_position++; diff --git a/fml/command_line.cc b/fml/command_line.cc index 79f27f2d76bce..db02addedf0ef 100644 --- a/fml/command_line.cc +++ b/fml/command_line.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #include "flutter/fml/command_line.h" @@ -27,8 +26,9 @@ CommandLine::CommandLine(const std::string& argv0, argv0_(argv0), options_(options), positional_args_(positional_args) { - for (size_t i = 0; i < options_.size(); i++) + for (size_t i = 0; i < options_.size(); i++) { option_index_[options_[i].name] = i; + } } CommandLine::~CommandLine() = default; @@ -39,18 +39,21 @@ CommandLine& CommandLine::operator=(CommandLine&& from) = default; bool CommandLine::HasOption(std::string_view name, size_t* index) const { auto it = option_index_.find(name.data()); - if (it == option_index_.end()) + if (it == option_index_.end()) { return false; - if (index) + } + if (index) { *index = it->second; + } return true; } bool CommandLine::GetOptionValue(std::string_view name, std::string* value) const { size_t index; - if (!HasOption(name, &index)) + if (!HasOption(name, &index)) { return false; + } *value = options_[index].value; return true; } @@ -59,8 +62,9 @@ std::vector CommandLine::GetOptionValues( std::string_view name) const { std::vector ret; for (const auto& option : options_) { - if (option.name == name) + if (option.name == name) { ret.push_back(option.value); + } } return ret; } @@ -69,8 +73,9 @@ std::string CommandLine::GetOptionValueWithDefault( std::string_view name, std::string_view default_value) const { size_t index; - if (!HasOption(name, &index)) + if (!HasOption(name, &index)) { return {default_value.data(), default_value.size()}; + } return options_[index].value; } @@ -125,16 +130,18 @@ bool CommandLineBuilder::ProcessArg(const std::string& arg) { } CommandLine CommandLineBuilder::Build() const { - if (!has_argv0_) + if (!has_argv0_) { return CommandLine(); + } return CommandLine(argv0_, options_, positional_args_); } } // namespace internal std::vector CommandLineToArgv(const CommandLine& command_line) { - if (!command_line.has_argv0()) + if (!command_line.has_argv0()) { return std::vector(); + } std::vector argv; const std::vector& options = command_line.options(); @@ -146,17 +153,19 @@ std::vector CommandLineToArgv(const CommandLine& command_line) { argv.push_back(command_line.argv0()); for (const auto& option : options) { - if (option.value.empty()) + if (option.value.empty()) { argv.push_back("--" + option.name); - else + } else { argv.push_back("--" + option.name + "=" + option.value); + } } if (!positional_args.empty()) { // Insert a "--" if necessary. if (positional_args[0].size() >= 2u && positional_args[0][0] == '-' && - positional_args[0][1] == '-') + positional_args[0][1] == '-') { argv.push_back("--"); + } argv.insert(argv.end(), positional_args.begin(), positional_args.end()); } diff --git a/fml/icu_util.cc b/fml/icu_util.cc index 302416ad4fa42..d05c68677582f 100644 --- a/fml/icu_util.cc +++ b/fml/icu_util.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #include "flutter/fml/icu_util.h" @@ -20,11 +19,12 @@ namespace icu { class ICUContext { public: - ICUContext(const std::string& icu_data_path) : valid_(false) { + explicit ICUContext(const std::string& icu_data_path) : valid_(false) { valid_ = SetupMapping(icu_data_path) && SetupICU(); } - ICUContext(std::unique_ptr mapping) : mapping_(std::move(mapping)) { + explicit ICUContext(std::unique_ptr mapping) + : mapping_(std::move(mapping)) { valid_ = SetupICU(); } diff --git a/fml/logging.cc b/fml/logging.cc index 5c9b20d17d318..8c4796db0a504 100644 --- a/fml/logging.cc +++ b/fml/logging.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #include #include @@ -23,23 +22,26 @@ const char* const kLogSeverityNames[LOG_NUM_SEVERITIES] = {"INFO", "WARNING", "ERROR", "FATAL"}; const char* GetNameForLogSeverity(LogSeverity severity) { - if (severity >= LOG_INFO && severity < LOG_NUM_SEVERITIES) + if (severity >= LOG_INFO && severity < LOG_NUM_SEVERITIES) { return kLogSeverityNames[severity]; + } return "UNKNOWN"; } const char* StripDots(const char* path) { - while (strncmp(path, "../", 3) == 0) + while (strncmp(path, "../", 3) == 0) { path += 3; + } return path; } const char* StripPath(const char* path) { auto* p = strrchr(path, '/'); - if (p) + if (p) { return p + 1; - else + } else { return path; + } } } // namespace @@ -50,15 +52,17 @@ LogMessage::LogMessage(LogSeverity severity, const char* condition) : severity_(severity), file_(file), line_(line) { stream_ << "["; - if (severity >= LOG_INFO) + if (severity >= LOG_INFO) { stream_ << GetNameForLogSeverity(severity); - else + } else { stream_ << "VERBOSE" << -severity; + } stream_ << ":" << (severity > LOG_INFO ? StripDots(file_) : StripPath(file_)) << "(" << line_ << ")] "; - if (condition) + if (condition) { stream_ << "Check failed: " << condition << ". "; + } } LogMessage::~LogMessage() { diff --git a/fml/memory/ref_counted_unittest.cc b/fml/memory/ref_counted_unittest.cc index a50e2aa5e7783..959117c488e38 100644 --- a/fml/memory/ref_counted_unittest.cc +++ b/fml/memory/ref_counted_unittest.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT // This file tests both ref_counted.h and ref_ptr.h (which the former includes). // TODO(vtl): Possibly we could separate these tests out better, since a lot of @@ -47,12 +46,14 @@ class MyClass : public RefCountedThreadSafe { protected: MyClass(MyClass** created, bool* was_destroyed) : was_destroyed_(was_destroyed) { - if (created) + if (created) { *created = this; + } } virtual ~MyClass() { - if (was_destroyed_) + if (was_destroyed_) { *was_destroyed_ = true; + } } private: @@ -71,8 +72,9 @@ class MySubclass final : public MyClass { MySubclass(MySubclass** created, bool* was_destroyed) : MyClass(nullptr, was_destroyed) { - if (created) + if (created) { *created = this; + } } ~MySubclass() override {} @@ -225,7 +227,7 @@ TEST(RefCountedTest, NullAssignmentToNull) { // No-op null assignment using move constructor. r1 = std::move(r2); EXPECT_TRUE(r1.get() == nullptr); - EXPECT_TRUE(r2.get() == nullptr); + EXPECT_TRUE(r2.get() == nullptr); // NOLINT(clang-analyzer-cplusplus.Move) EXPECT_FALSE(r1); EXPECT_FALSE(r2); @@ -270,7 +272,7 @@ TEST(RefCountedTest, NonNullAssignmentToNull) { RefPtr r2; // Move assignment (to null ref pointer). r2 = std::move(r1); - EXPECT_TRUE(r1.get() == nullptr); + EXPECT_TRUE(r1.get() == nullptr); // NOLINT(clang-analyzer-cplusplus.Move) EXPECT_EQ(created, r2.get()); EXPECT_FALSE(r1); EXPECT_TRUE(r2); @@ -334,7 +336,7 @@ TEST(RefCountedTest, NullAssignmentToNonNull) { // Null assignment using move constructor. r1 = std::move(r2); EXPECT_TRUE(r1.get() == nullptr); - EXPECT_TRUE(r2.get() == nullptr); + EXPECT_TRUE(r2.get() == nullptr); // NOLINT(clang-analyzer-cplusplus.Move) EXPECT_FALSE(r1); EXPECT_FALSE(r2); EXPECT_TRUE(was_destroyed); @@ -387,7 +389,7 @@ TEST(RefCountedTest, NonNullAssignmentToNonNull) { RefPtr r2(MakeRefCounted(nullptr, &was_destroyed2)); // Move assignment (to non-null ref pointer). r2 = std::move(r1); - EXPECT_TRUE(r1.get() == nullptr); + EXPECT_TRUE(r1.get() == nullptr); // NOLINT(clang-analyzer-cplusplus.Move) EXPECT_FALSE(r2.get() == nullptr); EXPECT_FALSE(r1); EXPECT_TRUE(r2); @@ -596,13 +598,14 @@ TEST(RefCountedTest, PublicCtorAndDtor) { TEST(RefCountedTest, DebugChecks) { { MyPublicClass* p = new MyPublicClass(); - EXPECT_DEATH_IF_SUPPORTED(delete p, "!adoption_required_"); + EXPECT_DEATH_IF_SUPPORTED( // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks) + delete p, "!adoption_required_"); } { MyPublicClass* p = new MyPublicClass(); - EXPECT_DEATH_IF_SUPPORTED(RefPtr r(p), - "!adoption_required_"); + EXPECT_DEATH_IF_SUPPORTED( // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks) + RefPtr r(p), "!adoption_required_"); } { diff --git a/fml/memory/ref_ptr.h b/fml/memory/ref_ptr.h index 51ebccc5e77bb..0321eda714dc5 100644 --- a/fml/memory/ref_ptr.h +++ b/fml/memory/ref_ptr.h @@ -66,7 +66,8 @@ template class RefPtr final { public: RefPtr() : ptr_(nullptr) {} - RefPtr(std::nullptr_t) : ptr_(nullptr) {} + RefPtr(std::nullptr_t) + : ptr_(nullptr) {} // NOLINT(google-explicit-constructor) // Explicit constructor from a plain pointer (to an object that must have // already been adopted). (Note that in |T::T()|, references to |this| cannot @@ -74,34 +75,39 @@ class RefPtr final { // yet.) template explicit RefPtr(U* p) : ptr_(p) { - if (ptr_) + if (ptr_) { ptr_->AddRef(); + } } // Copy constructor. RefPtr(const RefPtr& r) : ptr_(r.ptr_) { - if (ptr_) + if (ptr_) { ptr_->AddRef(); + } } template - RefPtr(const RefPtr& r) : ptr_(r.ptr_) { - if (ptr_) + RefPtr(const RefPtr& r) + : ptr_(r.ptr_) { // NOLINT(google-explicit-constructor) + if (ptr_) { ptr_->AddRef(); + } } // Move constructor. RefPtr(RefPtr&& r) : ptr_(r.ptr_) { r.ptr_ = nullptr; } template - RefPtr(RefPtr&& r) : ptr_(r.ptr_) { + RefPtr(RefPtr&& r) : ptr_(r.ptr_) { // NOLINT(google-explicit-constructor) r.ptr_ = nullptr; } // Destructor. ~RefPtr() { - if (ptr_) + if (ptr_) { ptr_->Release(); + } } T* get() const { return ptr_; } @@ -118,25 +124,34 @@ class RefPtr final { // Copy assignment. RefPtr& operator=(const RefPtr& r) { - // Call |AddRef()| first so self-assignments work. - if (r.ptr_) + // Handle self-assignment. + if (r.ptr_ == ptr_) { + return *this; + } + if (r.ptr_) { r.ptr_->AddRef(); + } T* old_ptr = ptr_; ptr_ = r.ptr_; - if (old_ptr) + if (old_ptr) { old_ptr->Release(); + } return *this; } template RefPtr& operator=(const RefPtr& r) { - // Call |AddRef()| first so self-assignments work. - if (r.ptr_) + if (reinterpret_cast(r.ptr_) == ptr_) { + return *this; + } + if (r.ptr_) { r.ptr_->AddRef(); + } T* old_ptr = ptr_; ptr_ = r.ptr_; - if (old_ptr) + if (old_ptr) { old_ptr->Release(); + } return *this; } diff --git a/fml/memory/weak_ptr_unittest.cc b/fml/memory/weak_ptr_unittest.cc index 8a02ff8c42c32..a1db3ae1d1988 100644 --- a/fml/memory/weak_ptr_unittest.cc +++ b/fml/memory/weak_ptr_unittest.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #define FML_USED_ON_EMBEDDER @@ -39,7 +38,7 @@ TEST(WeakPtrTest, MoveConstruction) { WeakPtrFactory factory(&data); WeakPtr ptr = factory.GetWeakPtr(); WeakPtr ptr2(std::move(ptr)); - EXPECT_EQ(nullptr, ptr.get()); + EXPECT_EQ(nullptr, ptr.get()); // NOLINT EXPECT_EQ(&data, ptr2.get()); } @@ -61,7 +60,7 @@ TEST(WeakPtrTest, MoveAssignment) { WeakPtr ptr2; EXPECT_EQ(nullptr, ptr2.get()); ptr2 = std::move(ptr); - EXPECT_EQ(nullptr, ptr.get()); + EXPECT_EQ(nullptr, ptr.get()); // NOLINT EXPECT_EQ(&data, ptr2.get()); } diff --git a/fml/message_loop_task_queues_benchmark.cc b/fml/message_loop_task_queues_benchmark.cc index 582c012012f86..065a7c3cc1b0c 100644 --- a/fml/message_loop_task_queues_benchmark.cc +++ b/fml/message_loop_task_queues_benchmark.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #include #include @@ -14,7 +13,7 @@ namespace fml { namespace benchmarking { -static void BM_RegisterAndGetTasks(benchmark::State& state) { +static void BM_RegisterAndGetTasks(benchmark::State& state) { // NOLINT while (state.KeepRunning()) { auto task_queue = fml::MessageLoopTaskQueues::GetInstance(); diff --git a/fml/message_loop_task_queues_merge_unmerge_unittests.cc b/fml/message_loop_task_queues_merge_unmerge_unittests.cc index 55e4a7eaedba1..808183ee0c8e9 100644 --- a/fml/message_loop_task_queues_merge_unmerge_unittests.cc +++ b/fml/message_loop_task_queues_merge_unmerge_unittests.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #define FML_USED_ON_EMBEDDER @@ -16,7 +15,7 @@ class TestWakeable : public fml::Wakeable { public: using WakeUpCall = std::function; - TestWakeable(WakeUpCall call) : wake_up_call_(call) {} + explicit TestWakeable(WakeUpCall call) : wake_up_call_(call) {} void WakeUp(fml::TimePoint time_point) override { wake_up_call_(time_point); } diff --git a/fml/message_loop_task_queues_unittests.cc b/fml/message_loop_task_queues_unittests.cc index 258afa9565c3d..a1c2df0a47f6c 100644 --- a/fml/message_loop_task_queues_unittests.cc +++ b/fml/message_loop_task_queues_unittests.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #define FML_USED_ON_EMBEDDER @@ -16,7 +15,7 @@ class TestWakeable : public fml::Wakeable { public: using WakeUpCall = std::function; - TestWakeable(WakeUpCall call) : wake_up_call_(call) {} + explicit TestWakeable(WakeUpCall call) : wake_up_call_(call) {} void WakeUp(fml::TimePoint time_point) override { wake_up_call_(time_point); } diff --git a/fml/message_loop_unittests.cc b/fml/message_loop_unittests.cc index 1a19bb4b4b3ea..34a7216a3467f 100644 --- a/fml/message_loop_unittests.cc +++ b/fml/message_loop_unittests.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #define FML_USED_ON_EMBEDDER @@ -16,7 +15,7 @@ #include "flutter/fml/task_runner.h" #include "gtest/gtest.h" -#define TIME_SENSITIVE(x) TimeSensitiveTest_##x +#define TIMESENSITIVE(x) TimeSensitiveTest_##x #if OS_WIN #define PLATFORM_SPECIFIC_CAPTURE(...) [ __VA_ARGS__, count ] #else @@ -154,7 +153,7 @@ TEST(MessageLoop, CheckRunsTaskOnCurrentThread) { thread.join(); } -TEST(MessageLoop, TIME_SENSITIVE(SingleDelayedTaskByDelta)) { +TEST(MessageLoop, TIMESENSITIVE(SingleDelayedTaskByDelta)) { bool checked = false; std::thread thread([&checked]() { fml::MessageLoop::EnsureInitializedForCurrentThread(); @@ -176,7 +175,7 @@ TEST(MessageLoop, TIME_SENSITIVE(SingleDelayedTaskByDelta)) { ASSERT_TRUE(checked); } -TEST(MessageLoop, TIME_SENSITIVE(SingleDelayedTaskForTime)) { +TEST(MessageLoop, TIMESENSITIVE(SingleDelayedTaskForTime)) { bool checked = false; std::thread thread([&checked]() { fml::MessageLoop::EnsureInitializedForCurrentThread(); @@ -198,7 +197,7 @@ TEST(MessageLoop, TIME_SENSITIVE(SingleDelayedTaskForTime)) { ASSERT_TRUE(checked); } -TEST(MessageLoop, TIME_SENSITIVE(MultipleDelayedTasksWithIncreasingDeltas)) { +TEST(MessageLoop, TIMESENSITIVE(MultipleDelayedTasksWithIncreasingDeltas)) { const auto count = 10; int checked = false; std::thread thread(PLATFORM_SPECIFIC_CAPTURE(&checked)() { @@ -225,7 +224,7 @@ TEST(MessageLoop, TIME_SENSITIVE(MultipleDelayedTasksWithIncreasingDeltas)) { ASSERT_EQ(checked, count); } -TEST(MessageLoop, TIME_SENSITIVE(MultipleDelayedTasksWithDecreasingDeltas)) { +TEST(MessageLoop, TIMESENSITIVE(MultipleDelayedTasksWithDecreasingDeltas)) { const auto count = 10; int checked = false; std::thread thread(PLATFORM_SPECIFIC_CAPTURE(&checked)() { diff --git a/fml/paths.cc b/fml/paths.cc index f8df002191a5d..1566726f053d1 100644 --- a/fml/paths.cc +++ b/fml/paths.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #include "flutter/fml/paths.h" @@ -35,12 +34,15 @@ std::string SanitizeURIEscapedCharacters(const std::string& str) { result.reserve(str.size()); for (std::string::size_type i = 0; i < str.size(); ++i) { if (str[i] == '%') { - if (i > str.size() - 3 || !isxdigit(str[i + 1]) || !isxdigit(str[i + 2])) + if (i > str.size() - 3 || !isxdigit(str[i + 1]) || + !isxdigit(str[i + 2])) { return ""; + } const std::string hex = str.substr(i + 1, 2); const unsigned char c = strtoul(hex.c_str(), nullptr, 16); - if (!c) + if (!c) { return ""; + } result += c; i += 2; } else { diff --git a/fml/platform/darwin/string_range_sanitization.mm b/fml/platform/darwin/string_range_sanitization.mm index e864ac652a60e..8100ba9154bf7 100644 --- a/fml/platform/darwin/string_range_sanitization.mm +++ b/fml/platform/darwin/string_range_sanitization.mm @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #include "flutter/fml/platform/darwin/string_range_sanitization.h" diff --git a/fml/platform/posix/paths_posix.cc b/fml/platform/posix/paths_posix.cc index 31d277b437ada..5defe8b9489e5 100644 --- a/fml/platform/posix/paths_posix.cc +++ b/fml/platform/posix/paths_posix.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #include "flutter/fml/paths.h" @@ -41,16 +40,19 @@ std::string AbsolutePath(const std::string& path) { std::string GetDirectoryName(const std::string& path) { size_t separator = path.rfind('/'); - if (separator == 0u) + if (separator == 0u) { return "/"; - if (separator == std::string::npos) + } + if (separator == std::string::npos) { return std::string(); + } return path.substr(0, separator); } std::string FromURI(const std::string& uri) { - if (uri.substr(0, kFileURLPrefixLength) != kFileURLPrefix) + if (uri.substr(0, kFileURLPrefixLength) != kFileURLPrefix) { return uri; + } std::string file_path = uri.substr(kFileURLPrefixLength); return SanitizeURIEscapedCharacters(file_path); diff --git a/fml/raster_thread_merger.cc b/fml/raster_thread_merger.cc index 47d3ad2e09fef..b29c303371b8a 100644 --- a/fml/raster_thread_merger.cc +++ b/fml/raster_thread_merger.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #define FML_USED_ON_EMBEDDER @@ -43,7 +42,8 @@ bool RasterThreadMerger::IsOnRasterizingThread() const { void RasterThreadMerger::ExtendLeaseTo(size_t lease_term) { FML_DCHECK(lease_term > 0) << "lease_term should be positive."; - if (lease_term_ != kLeaseNotSet && (int)lease_term > lease_term_) { + if (lease_term_ != kLeaseNotSet && + static_cast(lease_term) > lease_term_) { lease_term_ = lease_term; } } diff --git a/fml/synchronization/waitable_event.cc b/fml/synchronization/waitable_event.cc index 31af124fc8daf..cc2753ae0ba39 100644 --- a/fml/synchronization/waitable_event.cc +++ b/fml/synchronization/waitable_event.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #include "flutter/fml/synchronization/waitable_event.h" @@ -24,29 +23,33 @@ bool WaitWithTimeoutImpl(std::unique_lock* locker, TimeDelta timeout) { FML_DCHECK(locker->owns_lock()); - if (condition()) + if (condition()) { return false; + } // We may get spurious wakeups. TimeDelta wait_remaining = timeout; TimePoint start = TimePoint::Now(); while (true) { if (std::cv_status::timeout == - cv->wait_for(*locker, - std::chrono::nanoseconds(wait_remaining.ToNanoseconds()))) + cv->wait_for(*locker, std::chrono::nanoseconds( + wait_remaining.ToNanoseconds()))) { return true; // Definitely timed out. + } // We may have been awoken. - if (condition()) + if (condition()) { return false; + } // Or the wakeup may have been spurious. TimePoint now = TimePoint::Now(); FML_DCHECK(now >= start); TimeDelta elapsed = now - start; // It's possible that we may have timed out anyway. - if (elapsed >= timeout) + if (elapsed >= timeout) { return true; + } // Otherwise, recalculate the amount that we have left to wait. wait_remaining = timeout - elapsed; @@ -68,8 +71,9 @@ void AutoResetWaitableEvent::Reset() { void AutoResetWaitableEvent::Wait() { std::unique_lock locker(mutex_); - while (!signaled_) + while (!signaled_) { cv_.wait(locker); + } signaled_ = false; } @@ -86,21 +90,24 @@ bool AutoResetWaitableEvent::WaitWithTimeout(TimeDelta timeout) { TimePoint start = TimePoint::Now(); while (true) { if (std::cv_status::timeout == - cv_.wait_for(locker, - std::chrono::nanoseconds(wait_remaining.ToNanoseconds()))) + cv_.wait_for( + locker, std::chrono::nanoseconds(wait_remaining.ToNanoseconds()))) { return true; // Definitely timed out. + } // We may have been awoken. - if (signaled_) + if (signaled_) { break; + } // Or the wakeup may have been spurious. TimePoint now = TimePoint::Now(); FML_DCHECK(now >= start); TimeDelta elapsed = now - start; // It's possible that we may have timed out anyway. - if (elapsed >= timeout) + if (elapsed >= timeout) { return true; + } // Otherwise, recalculate the amount that we have left to wait. wait_remaining = timeout - elapsed; @@ -132,8 +139,9 @@ void ManualResetWaitableEvent::Reset() { void ManualResetWaitableEvent::Wait() { std::unique_lock locker(mutex_); - if (signaled_) + if (signaled_) { return; + } auto last_signal_id = signal_id_; do { diff --git a/fml/synchronization/waitable_event_unittest.cc b/fml/synchronization/waitable_event_unittest.cc index a5f59c4047b2c..63bcd5fd01b02 100644 --- a/fml/synchronization/waitable_event_unittest.cc +++ b/fml/synchronization/waitable_event_unittest.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #include "flutter/fml/synchronization/waitable_event.h" @@ -75,10 +74,11 @@ TEST(AutoResetWaitableEventTest, MultipleWaiters) { std::vector threads; for (size_t j = 0u; j < 4u; j++) { threads.push_back(std::thread([&ev, &wake_count]() { - if (rand() % 2 == 0) + if (rand() % 2 == 0) { ev.Wait(); - else + } else { EXPECT_FALSE(ev.WaitWithTimeout(kActionTimeout)); + } wake_count.fetch_add(1u); // Note: We can't say anything about the signaled state of |ev| here, // since the main thread may have already signaled it again. @@ -98,8 +98,9 @@ TEST(AutoResetWaitableEventTest, MultipleWaiters) { ev.Signal(); // Poll for |wake_count| to change. - while (wake_count.load() == old_wake_count) + while (wake_count.load() == old_wake_count) { SleepFor(kEpsilonTimeout); + } EXPECT_FALSE(ev.IsSignaledForTest()); @@ -117,8 +118,9 @@ TEST(AutoResetWaitableEventTest, MultipleWaiters) { SleepFor(kEpsilonTimeout); EXPECT_TRUE(ev.IsSignaledForTest()); - for (auto& thread : threads) + for (auto& thread : threads) { thread.join(); + } ev.Reset(); } @@ -157,10 +159,11 @@ TEST(ManualResetWaitableEventTest, SignalMultiple) { threads.push_back(std::thread([&ev]() { EpsilonRandomSleep(); - if (rand() % 2 == 0) + if (rand() % 2 == 0) { ev.Wait(); - else + } else { EXPECT_FALSE(ev.WaitWithTimeout(kActionTimeout)); + } })); } @@ -170,8 +173,9 @@ TEST(ManualResetWaitableEventTest, SignalMultiple) { // The threads will only terminate once they've successfully waited (or // timed out). - for (auto& thread : threads) + for (auto& thread : threads) { thread.join(); + } ev.Reset(); } diff --git a/fml/thread_local_unittests.cc b/fml/thread_local_unittests.cc index da00fc5d00b80..88e2bda1db6ce 100644 --- a/fml/thread_local_unittests.cc +++ b/fml/thread_local_unittests.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #include #include @@ -14,7 +13,7 @@ namespace { class Box { public: - Box(int value, std::atomic_int* destroys = nullptr) + explicit Box(int value, std::atomic_int* destroys = nullptr) : value_(value), destroys_(destroys) {} ~Box() { if (destroys_) { diff --git a/tools/font-subset/main.cc b/tools/font-subset/main.cc index 722fd13ba2eda..cbacb46d23c04 100644 --- a/tools/font-subset/main.cc +++ b/tools/font-subset/main.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #include #include @@ -14,7 +13,7 @@ #include "hb_wrappers.h" hb_codepoint_t ParseCodepoint(const std::string& arg) { - unsigned long value = 0; + uint64_t value = 0; // Check for \u123, u123, otherwise let strtoul work it out. if (arg[0] == 'u') { value = strtoul(arg.c_str() + 1, nullptr, 16);