Skip to content

Commit

Permalink
Use empty in place of size checks vs 0 (flutter#33151)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbracken authored May 6, 2022
1 parent c66257f commit e23c431
Show file tree
Hide file tree
Showing 46 changed files with 78 additions and 79 deletions.
6 changes: 3 additions & 3 deletions assets/asset_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ std::deque<std::unique_ptr<AssetResolver>> AssetManager::TakeResolvers() {
// |AssetResolver|
std::unique_ptr<fml::Mapping> AssetManager::GetAsMapping(
const std::string& asset_name) const {
if (asset_name.size() == 0) {
if (asset_name.empty()) {
return nullptr;
}
TRACE_EVENT1("flutter", "AssetManager::GetAsMapping", "name",
Expand All @@ -80,7 +80,7 @@ std::vector<std::unique_ptr<fml::Mapping>> AssetManager::GetAsMappings(
const std::string& asset_pattern,
const std::optional<std::string>& subdir) const {
std::vector<std::unique_ptr<fml::Mapping>> mappings;
if (asset_pattern.size() == 0) {
if (asset_pattern.empty()) {
return mappings;
}
TRACE_EVENT1("flutter", "AssetManager::GetAsMappings", "pattern",
Expand All @@ -96,7 +96,7 @@ std::vector<std::unique_ptr<fml::Mapping>> AssetManager::GetAsMappings(

// |AssetResolver|
bool AssetManager::IsValid() const {
return resolvers_.size() > 0;
return !resolvers_.empty();
}

// |AssetResolver|
Expand Down
4 changes: 2 additions & 2 deletions common/graphics/persistent_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ sk_sp<SkData> PersistentCache::load(const SkData& key) {
return nullptr;
}
auto file_name = SkKeyToFilePath(key);
if (file_name.size() == 0) {
if (file_name.empty()) {
return nullptr;
}
auto result =
Expand Down Expand Up @@ -405,7 +405,7 @@ void PersistentCache::store(const SkData& key, const SkData& data) {

auto file_name = SkKeyToFilePath(key);

if (file_name.size() == 0) {
if (file_name.empty()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion flow/skia_gpu_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class UnrefQueue : public fml::RefCountedThreadSafe<UnrefQueue<T>> {
skia_object->unref();
}

if (context && skia_objects.size() > 0) {
if (context && !skia_objects.empty()) {
context->performDeferredCleanup(std::chrono::milliseconds(0));
}
}
Expand Down
4 changes: 2 additions & 2 deletions fml/concurrent_message_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ void ConcurrentMessageLoop::WorkerMain() {
while (true) {
std::unique_lock lock(tasks_mutex_);
tasks_condition_.wait(lock, [&]() {
return tasks_.size() > 0 || shutdown_ || HasThreadTasksLocked();
return !tasks_.empty() || shutdown_ || HasThreadTasksLocked();
});

// Shutdown cannot be read with the task mutex unlocked.
bool shutdown_now = shutdown_;
fml::closure task;
std::vector<fml::closure> thread_tasks;

if (tasks_.size() != 0) {
if (!tasks_.empty()) {
task = tasks_.front();
tasks_.pop();
}
Expand Down
2 changes: 1 addition & 1 deletion fml/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fml::UniqueFD CreateDirectory(const fml::UniqueFD& base_directory,
return {};
}

if (components.size() == 0) {
if (components.empty()) {
return {};
}

Expand Down
4 changes: 2 additions & 2 deletions fml/mapping.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ std::unique_ptr<FileMapping> FileMapping::CreateReadOnly(
std::unique_ptr<FileMapping> FileMapping::CreateReadOnly(
const fml::UniqueFD& base_fd,
const std::string& sub_path) {
if (sub_path.size() != 0) {
if (!sub_path.empty()) {
return CreateReadOnly(
OpenFile(base_fd, sub_path.c_str(), false, FilePermission::kRead), "");
}
Expand All @@ -48,7 +48,7 @@ std::unique_ptr<FileMapping> FileMapping::CreateReadExecute(
std::unique_ptr<FileMapping> FileMapping::CreateReadExecute(
const fml::UniqueFD& base_fd,
const std::string& sub_path) {
if (sub_path.size() != 0) {
if (!sub_path.empty()) {
return CreateReadExecute(
OpenFile(base_fd, sub_path.c_str(), false, FilePermission::kRead), "");
}
Expand Down
2 changes: 1 addition & 1 deletion fml/platform/posix/paths_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ std::string GetCurrentDirectory() {
} // namespace

std::string AbsolutePath(const std::string& path) {
if (path.size() > 0) {
if (!path.empty()) {
if (path[0] == '/') {
// Path is already absolute.
return path;
Expand Down
8 changes: 4 additions & 4 deletions fml/platform/win/file_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static bool IsAbsolutePath(const char* path) {
}

auto wpath = Utf8ToWideString({path});
if (wpath.size() == 0) {
if (wpath.empty()) {
return false;
}

Expand Down Expand Up @@ -107,7 +107,7 @@ static DWORD GetFileAttributesForUtf8Path(const fml::UniqueFD& base_directory,
std::string CreateTemporaryDirectory() {
// Get the system temporary directory.
auto temp_dir_container = GetTemporaryDirectoryPath();
if (temp_dir_container.size() == 0) {
if (temp_dir_container.empty()) {
FML_DLOG(ERROR) << "Could not get system temporary directory.";
return {};
}
Expand Down Expand Up @@ -164,7 +164,7 @@ fml::UniqueFD OpenFile(const char* path,

auto file_name = Utf8ToWideString({path});

if (file_name.size() == 0) {
if (file_name.empty()) {
return {};
}

Expand Down Expand Up @@ -207,7 +207,7 @@ fml::UniqueFD OpenDirectory(const char* path,

auto file_name = Utf8ToWideString({path});

if (file_name.size() == 0) {
if (file_name.empty()) {
return {};
}

Expand Down
2 changes: 1 addition & 1 deletion fml/platform/win/paths_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ constexpr char kFileURLPrefix[] = "file:///";
constexpr size_t kFileURLPrefixLength = sizeof(kFileURLPrefix) - 1;

size_t RootLength(const std::string& path) {
if (path.size() == 0)
if (path.empty())
return 0;
if (path[0] == '/')
return 1;
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/dart_runtime_hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void Logger_PrintString(Dart_NativeArguments args) {

if (dart::bin::ShouldCaptureStdout()) {
std::stringstream stream;
if (tag.size() > 0) {
if (!tag.empty()) {
stream << tag << ": ";
}
stream << message;
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/ui_dart_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,14 @@ void UIDartState::LogMessage(const std::string& tag,
(int)message.size(), message.c_str());
#elif defined(FML_OS_IOS)
std::stringstream stream;
if (tag.size() > 0) {
if (!tag.empty()) {
stream << tag << ": ";
}
stream << message;
std::string log = stream.str();
syslog(1 /* LOG_ALERT */, "%.*s", (int)log.size(), log.c_str());
#else
if (tag.size() > 0) {
if (!tag.empty()) {
std::cout << tag << ": ";
}
std::cout << message << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion runtime/dart_lifecycle_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static std::shared_ptr<DartIsolate> CreateAndRunRootIsolate(
const DartVMData& vm,
fml::RefPtr<fml::TaskRunner> task_runner,
std::string entrypoint) {
FML_CHECK(entrypoint.size() > 0);
FML_CHECK(!entrypoint.empty());
TaskRunners runners("io.flutter.test", task_runner, task_runner, task_runner,
task_runner);

Expand Down
2 changes: 1 addition & 1 deletion runtime/dart_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static std::shared_ptr<const fml::Mapping> SearchMapping(
}

// Attempt to open file at path specified.
if (file_path.size() > 0) {
if (!file_path.empty()) {
if (auto file_mapping = GetFileMapping(file_path, is_executable)) {
return file_mapping;
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/service_protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ bool ServiceProtocol::HandleMessage(std::string_view method,

fml::SharedLock lock(*handlers_mutex_);

if (handlers_.size() == 0) {
if (handlers_.empty()) {
WriteServerErrorResponse(response,
"There are no running service protocol handlers.");
return false;
Expand Down
2 changes: 1 addition & 1 deletion shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void PerformInitializationTasks(Settings& settings) {
}

if (settings.icu_initialization_required) {
if (settings.icu_data_path.size() != 0) {
if (!settings.icu_data_path.empty()) {
fml::icu::InitializeICU(settings.icu_data_path);
} else if (settings.icu_mapper) {
fml::icu::InitializeICUFromMapping(settings.icu_mapper());
Expand Down
4 changes: 2 additions & 2 deletions shell/common/shell_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static void ValidateDestroyPlatformView(Shell* shell) {
}

static std::string CreateFlagsString(std::vector<const char*>& flags) {
if (flags.size() == 0) {
if (flags.empty()) {
return "";
}
std::string flags_string = flags[0];
Expand Down Expand Up @@ -649,7 +649,7 @@ TEST_F(ShellTest, ReportTimingsIsCalled) {
DestroyShell(std::move(shell));

fml::TimePoint finish = fml::TimePoint::Now();
ASSERT_TRUE(timestamps.size() > 0);
ASSERT_TRUE(!timestamps.empty());
ASSERT_TRUE(timestamps.size() % FrameTiming::kCount == 0);
std::vector<FrameTiming> timings(timestamps.size() / FrameTiming::kCount);

Expand Down
4 changes: 2 additions & 2 deletions shell/common/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,11 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
FlagForSwitch(Switch::IsolateSnapshotInstructions),
&isolate_snapshot_instr_filename);

if (aot_shared_library_name.size() > 0) {
if (!aot_shared_library_name.empty()) {
for (std::string_view name : aot_shared_library_name) {
settings.application_library_path.emplace_back(name);
}
} else if (snapshot_asset_path.size() > 0) {
} else if (!snapshot_asset_path.empty()) {
settings.vm_snapshot_data_path =
fml::paths::JoinPaths({snapshot_asset_path, vm_snapshot_data_filename});
settings.vm_snapshot_instr_path = fml::paths::JoinPaths(
Expand Down
6 changes: 3 additions & 3 deletions shell/platform/android/android_shell_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,13 @@ std::optional<RunConfiguration> AndroidShellHolder::BuildRunConfiguration(
std::move(asset_manager));

{
if ((entrypoint.size() > 0) && (libraryUrl.size() > 0)) {
if (!entrypoint.empty() && !libraryUrl.empty()) {
config.SetEntrypointAndLibrary(std::move(entrypoint),
std::move(libraryUrl));
} else if (entrypoint.size() > 0) {
} else if (!entrypoint.empty()) {
config.SetEntrypoint(std::move(entrypoint));
}
if (entrypoint_args.size() > 0) {
if (!entrypoint_args.empty()) {
config.SetEntrypointArgs(std::move(entrypoint_args));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ PostPrerollResult AndroidExternalViewEmbedder::PostPrerollAction(
}

bool AndroidExternalViewEmbedder::FrameHasPlatformLayers() {
return composition_order_.size() > 0;
return !composition_order_.empty();
}

// |ExternalViewEmbedder|
Expand Down
4 changes: 2 additions & 2 deletions shell/platform/android/external_view_embedder/surface_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void SurfacePool::RecycleLayers() {

bool SurfacePool::HasLayers() {
std::lock_guard lock(mutex_);
return layers_.size() > 0;
return !layers_.empty();
}

void SurfacePool::DestroyLayers(
Expand All @@ -91,7 +91,7 @@ void SurfacePool::DestroyLayers(

void SurfacePool::DestroyLayersLocked(
std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
if (layers_.size() == 0) {
if (layers_.empty()) {
return;
}
jni_facade->FlutterViewDestroyOverlaySurfaces();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ void PlatformViewAndroidDelegate::UpdateSemantics(

// Calling NewDirectByteBuffer in API level 22 and below with a size of zero
// will cause a JNI crash.
if (actions_buffer.size() > 0) {
if (!actions_buffer.empty()) {
jni_facade_->FlutterViewUpdateCustomAccessibilityActions(actions_buffer,
action_strings);
}

if (buffer.size() > 0) {
if (!buffer.empty()) {
jni_facade_->FlutterViewUpdateSemantics(buffer, strings,
string_attribute_args);
}
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 @@ -263,7 +263,7 @@ void AccessibilityBridge::SetRoleFromFlutterUpdate(ui::AXNodeData& node_data,
}
// If the state cannot be derived from the flutter flags, we fallback to group
// or static text.
if (node.children_in_traversal_order.size() == 0) {
if (node.children_in_traversal_order.empty()) {
node_data.role = ax::mojom::Role::kStaticText;
} else {
node_data.role = ax::mojom::Role::kGroup;
Expand Down Expand Up @@ -346,7 +346,7 @@ void AccessibilityBridge::SetBooleanAttributesFromFlutterUpdate(
actions & FlutterSemanticsAction::kFlutterSemanticsActionTap);
// TODO(chunhtai): figure out if there is a node that does not clip overflow.
node_data.AddBoolAttribute(ax::mojom::BoolAttribute::kClipsChildren,
node.children_in_traversal_order.size() != 0);
!node.children_in_traversal_order.empty());
node_data.AddBoolAttribute(
ax::mojom::BoolAttribute::kSelected,
flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsSelected);
Expand Down
10 changes: 5 additions & 5 deletions shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
// TODO(cbracken): replace this with os_log-based approach.
// https://github.com/flutter/flutter/issues/44030
std::stringstream stream;
if (tag.size() > 0) {
if (!tag.empty()) {
stream << tag << ": ";
}
stream << message;
Expand All @@ -78,7 +78,7 @@
// defaults.

// Flutter ships the ICU data file in the bundle of the engine. Look for it there.
if (settings.icu_data_path.size() == 0) {
if (settings.icu_data_path.empty()) {
NSString* icuDataPath = [engineBundle pathForResource:@"icudtl" ofType:@"dat"];
if (icuDataPath.length > 0) {
settings.icu_data_path = icuDataPath.UTF8String;
Expand All @@ -94,7 +94,7 @@
}

// No application bundle specified. Try a known location from the main bundle's Info.plist.
if (settings.application_library_path.size() == 0) {
if (settings.application_library_path.empty()) {
NSString* libraryName = [mainBundle objectForInfoDictionaryKey:@"FLTLibraryPath"];
NSString* libraryPath = [mainBundle pathForResource:libraryName ofType:@""];
if (libraryPath.length > 0) {
Expand All @@ -107,7 +107,7 @@

// In case the application bundle is still not specified, look for the App.framework in the
// Frameworks directory.
if (settings.application_library_path.size() == 0) {
if (settings.application_library_path.empty()) {
NSString* applicationFrameworkPath = [mainBundle pathForResource:@"Frameworks/App.framework"
ofType:@""];
if (applicationFrameworkPath.length > 0) {
Expand All @@ -121,7 +121,7 @@
}

// Checks to see if the flutter assets directory is already present.
if (settings.assets_path.size() == 0) {
if (settings.assets_path.empty()) {
NSString* assetsName = [FlutterDartProject flutterAssetsName:bundle];
NSString* assetsPath = [bundle pathForResource:assetsName ofType:@""];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
// Make this method check if there are pending view operations instead.
// Also rename it to `HasPendingViewOperations`.
bool FlutterPlatformViewsController::HasPlatformViewThisOrNextFrame() {
return composition_order_.size() > 0 || active_composition_order_.size() > 0;
return !composition_order_.empty() || !active_composition_order_.empty();
}

const int FlutterPlatformViewsController::kDefaultMergedLeaseDuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void PostAccessibilityNotification(UIAccessibilityNotifications notification,
[newChildren addObject:child];
}
object.children = newChildren;
if (node.customAccessibilityActions.size() > 0) {
if (!node.customAccessibilityActions.empty()) {
NSMutableArray<FlutterCustomAccessibilityAction*>* accessibilityCustomActions =
[[[NSMutableArray alloc] init] autorelease];
for (int32_t action_id : node.customAccessibilityActions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
flutterArguments.assets_path = _project.assetsPath.UTF8String;
flutterArguments.icu_data_path = _project.ICUDataPath.UTF8String;
flutterArguments.command_line_argc = static_cast<int>(argv.size());
flutterArguments.command_line_argv = argv.size() > 0 ? argv.data() : nullptr;
flutterArguments.command_line_argv = argv.empty() ? nullptr : argv.data();
flutterArguments.platform_message_callback = (FlutterPlatformMessageCallback)OnPlatformMessage;
flutterArguments.update_semantics_node_callback = [](const FlutterSemanticsNode* node,
void* user_data) {
Expand Down
Loading

0 comments on commit e23c431

Please sign in to comment.