Skip to content

Commit e23c431

Browse files
authored
Use empty in place of size checks vs 0 (flutter#33151)
1 parent c66257f commit e23c431

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+78
-79
lines changed

assets/asset_manager.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ std::deque<std::unique_ptr<AssetResolver>> AssetManager::TakeResolvers() {
6060
// |AssetResolver|
6161
std::unique_ptr<fml::Mapping> AssetManager::GetAsMapping(
6262
const std::string& asset_name) const {
63-
if (asset_name.size() == 0) {
63+
if (asset_name.empty()) {
6464
return nullptr;
6565
}
6666
TRACE_EVENT1("flutter", "AssetManager::GetAsMapping", "name",
@@ -80,7 +80,7 @@ std::vector<std::unique_ptr<fml::Mapping>> AssetManager::GetAsMappings(
8080
const std::string& asset_pattern,
8181
const std::optional<std::string>& subdir) const {
8282
std::vector<std::unique_ptr<fml::Mapping>> mappings;
83-
if (asset_pattern.size() == 0) {
83+
if (asset_pattern.empty()) {
8484
return mappings;
8585
}
8686
TRACE_EVENT1("flutter", "AssetManager::GetAsMappings", "pattern",
@@ -96,7 +96,7 @@ std::vector<std::unique_ptr<fml::Mapping>> AssetManager::GetAsMappings(
9696

9797
// |AssetResolver|
9898
bool AssetManager::IsValid() const {
99-
return resolvers_.size() > 0;
99+
return !resolvers_.empty();
100100
}
101101

102102
// |AssetResolver|

common/graphics/persistent_cache.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ sk_sp<SkData> PersistentCache::load(const SkData& key) {
332332
return nullptr;
333333
}
334334
auto file_name = SkKeyToFilePath(key);
335-
if (file_name.size() == 0) {
335+
if (file_name.empty()) {
336336
return nullptr;
337337
}
338338
auto result =
@@ -405,7 +405,7 @@ void PersistentCache::store(const SkData& key, const SkData& data) {
405405

406406
auto file_name = SkKeyToFilePath(key);
407407

408-
if (file_name.size() == 0) {
408+
if (file_name.empty()) {
409409
return;
410410
}
411411

flow/skia_gpu_object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class UnrefQueue : public fml::RefCountedThreadSafe<UnrefQueue<T>> {
8989
skia_object->unref();
9090
}
9191

92-
if (context && skia_objects.size() > 0) {
92+
if (context && !skia_objects.empty()) {
9393
context->performDeferredCleanup(std::chrono::milliseconds(0));
9494
}
9595
}

fml/concurrent_message_loop.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ void ConcurrentMessageLoop::WorkerMain() {
7878
while (true) {
7979
std::unique_lock lock(tasks_mutex_);
8080
tasks_condition_.wait(lock, [&]() {
81-
return tasks_.size() > 0 || shutdown_ || HasThreadTasksLocked();
81+
return !tasks_.empty() || shutdown_ || HasThreadTasksLocked();
8282
});
8383

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

89-
if (tasks_.size() != 0) {
89+
if (!tasks_.empty()) {
9090
task = tasks_.front();
9191
tasks_.pop();
9292
}

fml/file.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fml::UniqueFD CreateDirectory(const fml::UniqueFD& base_directory,
3737
return {};
3838
}
3939

40-
if (components.size() == 0) {
40+
if (components.empty()) {
4141
return {};
4242
}
4343

fml/mapping.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ std::unique_ptr<FileMapping> FileMapping::CreateReadOnly(
2424
std::unique_ptr<FileMapping> FileMapping::CreateReadOnly(
2525
const fml::UniqueFD& base_fd,
2626
const std::string& sub_path) {
27-
if (sub_path.size() != 0) {
27+
if (!sub_path.empty()) {
2828
return CreateReadOnly(
2929
OpenFile(base_fd, sub_path.c_str(), false, FilePermission::kRead), "");
3030
}
@@ -48,7 +48,7 @@ std::unique_ptr<FileMapping> FileMapping::CreateReadExecute(
4848
std::unique_ptr<FileMapping> FileMapping::CreateReadExecute(
4949
const fml::UniqueFD& base_fd,
5050
const std::string& sub_path) {
51-
if (sub_path.size() != 0) {
51+
if (!sub_path.empty()) {
5252
return CreateReadExecute(
5353
OpenFile(base_fd, sub_path.c_str(), false, FilePermission::kRead), "");
5454
}

fml/platform/posix/paths_posix.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ std::string GetCurrentDirectory() {
2727
} // namespace
2828

2929
std::string AbsolutePath(const std::string& path) {
30-
if (path.size() > 0) {
30+
if (!path.empty()) {
3131
if (path[0] == '/') {
3232
// Path is already absolute.
3333
return path;

fml/platform/win/file_win.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static bool IsAbsolutePath(const char* path) {
4040
}
4141

4242
auto wpath = Utf8ToWideString({path});
43-
if (wpath.size() == 0) {
43+
if (wpath.empty()) {
4444
return false;
4545
}
4646

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

165165
auto file_name = Utf8ToWideString({path});
166166

167-
if (file_name.size() == 0) {
167+
if (file_name.empty()) {
168168
return {};
169169
}
170170

@@ -207,7 +207,7 @@ fml::UniqueFD OpenDirectory(const char* path,
207207

208208
auto file_name = Utf8ToWideString({path});
209209

210-
if (file_name.size() == 0) {
210+
if (file_name.empty()) {
211211
return {};
212212
}
213213

fml/platform/win/paths_win.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ constexpr char kFileURLPrefix[] = "file:///";
1919
constexpr size_t kFileURLPrefixLength = sizeof(kFileURLPrefix) - 1;
2020

2121
size_t RootLength(const std::string& path) {
22-
if (path.size() == 0)
22+
if (path.empty())
2323
return 0;
2424
if (path[0] == '/')
2525
return 1;

lib/ui/dart_runtime_hooks.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void Logger_PrintString(Dart_NativeArguments args) {
187187

188188
if (dart::bin::ShouldCaptureStdout()) {
189189
std::stringstream stream;
190-
if (tag.size() > 0) {
190+
if (!tag.empty()) {
191191
stream << tag << ": ";
192192
}
193193
stream << message;

lib/ui/ui_dart_state.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ void UIDartState::LogMessage(const std::string& tag,
197197
(int)message.size(), message.c_str());
198198
#elif defined(FML_OS_IOS)
199199
std::stringstream stream;
200-
if (tag.size() > 0) {
200+
if (!tag.empty()) {
201201
stream << tag << ": ";
202202
}
203203
stream << message;
204204
std::string log = stream.str();
205205
syslog(1 /* LOG_ALERT */, "%.*s", (int)log.size(), log.c_str());
206206
#else
207-
if (tag.size() > 0) {
207+
if (!tag.empty()) {
208208
std::cout << tag << ": ";
209209
}
210210
std::cout << message << std::endl;

runtime/dart_lifecycle_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static std::shared_ptr<DartIsolate> CreateAndRunRootIsolate(
4848
const DartVMData& vm,
4949
fml::RefPtr<fml::TaskRunner> task_runner,
5050
std::string entrypoint) {
51-
FML_CHECK(entrypoint.size() > 0);
51+
FML_CHECK(!entrypoint.empty());
5252
TaskRunners runners("io.flutter.test", task_runner, task_runner, task_runner,
5353
task_runner);
5454

runtime/dart_snapshot.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static std::shared_ptr<const fml::Mapping> SearchMapping(
6363
}
6464

6565
// Attempt to open file at path specified.
66-
if (file_path.size() > 0) {
66+
if (!file_path.empty()) {
6767
if (auto file_mapping = GetFileMapping(file_path, is_executable)) {
6868
return file_mapping;
6969
}

runtime/service_protocol.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ bool ServiceProtocol::HandleMessage(std::string_view method,
193193

194194
fml::SharedLock lock(*handlers_mutex_);
195195

196-
if (handlers_.size() == 0) {
196+
if (handlers_.empty()) {
197197
WriteServerErrorResponse(response,
198198
"There are no running service protocol handlers.");
199199
return false;

shell/common/shell.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void PerformInitializationTasks(Settings& settings) {
107107
}
108108

109109
if (settings.icu_initialization_required) {
110-
if (settings.icu_data_path.size() != 0) {
110+
if (!settings.icu_data_path.empty()) {
111111
fml::icu::InitializeICU(settings.icu_data_path);
112112
} else if (settings.icu_mapper) {
113113
fml::icu::InitializeICUFromMapping(settings.icu_mapper());

shell/common/shell_unittests.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ static void ValidateDestroyPlatformView(Shell* shell) {
237237
}
238238

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

651651
fml::TimePoint finish = fml::TimePoint::Now();
652-
ASSERT_TRUE(timestamps.size() > 0);
652+
ASSERT_TRUE(!timestamps.empty());
653653
ASSERT_TRUE(timestamps.size() % FrameTiming::kCount == 0);
654654
std::vector<FrameTiming> timings(timestamps.size() / FrameTiming::kCount);
655655

shell/common/switches.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,11 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
377377
FlagForSwitch(Switch::IsolateSnapshotInstructions),
378378
&isolate_snapshot_instr_filename);
379379

380-
if (aot_shared_library_name.size() > 0) {
380+
if (!aot_shared_library_name.empty()) {
381381
for (std::string_view name : aot_shared_library_name) {
382382
settings.application_library_path.emplace_back(name);
383383
}
384-
} else if (snapshot_asset_path.size() > 0) {
384+
} else if (!snapshot_asset_path.empty()) {
385385
settings.vm_snapshot_data_path =
386386
fml::paths::JoinPaths({snapshot_asset_path, vm_snapshot_data_filename});
387387
settings.vm_snapshot_instr_path = fml::paths::JoinPaths(

shell/platform/android/android_shell_holder.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,13 @@ std::optional<RunConfiguration> AndroidShellHolder::BuildRunConfiguration(
337337
std::move(asset_manager));
338338

339339
{
340-
if ((entrypoint.size() > 0) && (libraryUrl.size() > 0)) {
340+
if (!entrypoint.empty() && !libraryUrl.empty()) {
341341
config.SetEntrypointAndLibrary(std::move(entrypoint),
342342
std::move(libraryUrl));
343-
} else if (entrypoint.size() > 0) {
343+
} else if (!entrypoint.empty()) {
344344
config.SetEntrypoint(std::move(entrypoint));
345345
}
346-
if (entrypoint_args.size() > 0) {
346+
if (!entrypoint_args.empty()) {
347347
config.SetEntrypointArgs(std::move(entrypoint_args));
348348
}
349349
}

shell/platform/android/external_view_embedder/external_view_embedder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ PostPrerollResult AndroidExternalViewEmbedder::PostPrerollAction(
242242
}
243243

244244
bool AndroidExternalViewEmbedder::FrameHasPlatformLayers() {
245-
return composition_order_.size() > 0;
245+
return !composition_order_.empty();
246246
}
247247

248248
// |ExternalViewEmbedder|

shell/platform/android/external_view_embedder/surface_pool.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void SurfacePool::RecycleLayers() {
8080

8181
bool SurfacePool::HasLayers() {
8282
std::lock_guard lock(mutex_);
83-
return layers_.size() > 0;
83+
return !layers_.empty();
8484
}
8585

8686
void SurfacePool::DestroyLayers(
@@ -91,7 +91,7 @@ void SurfacePool::DestroyLayers(
9191

9292
void SurfacePool::DestroyLayersLocked(
9393
std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {
94-
if (layers_.size() == 0) {
94+
if (layers_.empty()) {
9595
return;
9696
}
9797
jni_facade->FlutterViewDestroyOverlaySurfaces();

shell/platform/android/platform_view_android_delegate/platform_view_android_delegate.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,12 @@ void PlatformViewAndroidDelegate::UpdateSemantics(
209209

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

217-
if (buffer.size() > 0) {
217+
if (!buffer.empty()) {
218218
jni_facade_->FlutterViewUpdateSemantics(buffer, strings,
219219
string_attribute_args);
220220
}

shell/platform/common/accessibility_bridge.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void AccessibilityBridge::SetRoleFromFlutterUpdate(ui::AXNodeData& node_data,
263263
}
264264
// If the state cannot be derived from the flutter flags, we fallback to group
265265
// or static text.
266-
if (node.children_in_traversal_order.size() == 0) {
266+
if (node.children_in_traversal_order.empty()) {
267267
node_data.role = ax::mojom::Role::kStaticText;
268268
} else {
269269
node_data.role = ax::mojom::Role::kGroup;
@@ -346,7 +346,7 @@ void AccessibilityBridge::SetBooleanAttributesFromFlutterUpdate(
346346
actions & FlutterSemanticsAction::kFlutterSemanticsActionTap);
347347
// TODO(chunhtai): figure out if there is a node that does not clip overflow.
348348
node_data.AddBoolAttribute(ax::mojom::BoolAttribute::kClipsChildren,
349-
node.children_in_traversal_order.size() != 0);
349+
!node.children_in_traversal_order.empty());
350350
node_data.AddBoolAttribute(
351351
ax::mojom::BoolAttribute::kSelected,
352352
flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsSelected);

shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
// TODO(cbracken): replace this with os_log-based approach.
6767
// https://github.com/flutter/flutter/issues/44030
6868
std::stringstream stream;
69-
if (tag.size() > 0) {
69+
if (!tag.empty()) {
7070
stream << tag << ": ";
7171
}
7272
stream << message;
@@ -78,7 +78,7 @@
7878
// defaults.
7979

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

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

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

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

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
// Make this method check if there are pending view operations instead.
256256
// Also rename it to `HasPendingViewOperations`.
257257
bool FlutterPlatformViewsController::HasPlatformViewThisOrNextFrame() {
258-
return composition_order_.size() > 0 || active_composition_order_.size() > 0;
258+
return !composition_order_.empty() || !active_composition_order_.empty();
259259
}
260260

261261
const int FlutterPlatformViewsController::kDefaultMergedLeaseDuration;

shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void PostAccessibilityNotification(UIAccessibilityNotifications notification,
104104
[newChildren addObject:child];
105105
}
106106
object.children = newChildren;
107-
if (node.customAccessibilityActions.size() > 0) {
107+
if (!node.customAccessibilityActions.empty()) {
108108
NSMutableArray<FlutterCustomAccessibilityAction*>* accessibilityCustomActions =
109109
[[[NSMutableArray alloc] init] autorelease];
110110
for (int32_t action_id : node.customAccessibilityActions) {

shell/platform/darwin/macos/framework/Source/FlutterEngine.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
282282
flutterArguments.assets_path = _project.assetsPath.UTF8String;
283283
flutterArguments.icu_data_path = _project.ICUDataPath.UTF8String;
284284
flutterArguments.command_line_argc = static_cast<int>(argv.size());
285-
flutterArguments.command_line_argv = argv.size() > 0 ? argv.data() : nullptr;
285+
flutterArguments.command_line_argv = argv.empty() ? nullptr : argv.data();
286286
flutterArguments.platform_message_callback = (FlutterPlatformMessageCallback)OnPlatformMessage;
287287
flutterArguments.update_semantics_node_callback = [](const FlutterSemanticsNode* node,
288288
void* user_data) {

0 commit comments

Comments
 (0)