Skip to content

Commit 554ad93

Browse files
authored
chore: prefer empty() check for readability (electron#26109)
1 parent d9db987 commit 554ad93

11 files changed

+15
-15
lines changed

shell/browser/api/electron_api_base_window.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ std::vector<v8::Local<v8::Object>> BaseWindow::GetChildWindows() const {
951951

952952
v8::Local<v8::Value> BaseWindow::GetBrowserView(
953953
gin_helper::Arguments* args) const {
954-
if (browser_views_.size() == 0) {
954+
if (browser_views_.empty()) {
955955
return v8::Null(isolate());
956956
} else if (browser_views_.size() == 1) {
957957
auto first_view = browser_views_.begin();

shell/browser/api/electron_api_web_contents.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ base::string16 GetDefaultPrinterAsync() {
406406
if (printer_name.empty()) {
407407
printing::PrinterList printers;
408408
print_backend->EnumeratePrinters(&printers);
409-
if (printers.size() > 0)
409+
if (!printers.empty())
410410
printer_name = printers.front().printer_name;
411411
}
412412
return base::UTF8ToUTF16(printer_name);
@@ -2187,7 +2187,7 @@ void WebContents::Print(gin::Arguments* args) {
21872187
continue;
21882188
}
21892189
}
2190-
if (page_range_list.GetList().size() > 0)
2190+
if (!page_range_list.GetList().empty())
21912191
settings.SetPath(printing::kSettingPageRange, std::move(page_range_list));
21922192
}
21932193

shell/browser/browser_win.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ std::vector<Browser::LaunchItem> GetLoginItemSettingsHelper(
203203
if ((base::CompareCaseInsensitiveASCII(it->Value(), exe.c_str())) == 0) {
204204
Browser::LaunchItem launch_item;
205205
base::string16 launch_path = options.path;
206-
if (!(launch_path.size() > 0)) {
206+
if (launch_path.empty()) {
207207
GetProcessExecPath(&launch_path);
208208
}
209209
launch_item.name = it->Name();
@@ -339,7 +339,7 @@ void GetApplicationInfoForProtocolUsingRegistry(
339339
}
340340
const base::string16 app_display_name = GetAppForProtocolUsingRegistry(url);
341341

342-
if (app_display_name.length() == 0) {
342+
if (app_display_name.empty()) {
343343
promise.RejectWithErrorMessage(
344344
"Unable to retrieve application display name");
345345
return;
@@ -607,7 +607,7 @@ void Browser::SetLoginItemSettings(LoginItemSettings settings) {
607607
base::win::RegKey startup_approved_key(
608608
HKEY_CURRENT_USER, startup_approved_key_path.c_str(), KEY_ALL_ACCESS);
609609
PCWSTR key_name =
610-
settings.name.size() > 0 ? settings.name.c_str() : GetAppUserModelID();
610+
!settings.name.empty() ? settings.name.c_str() : GetAppUserModelID();
611611

612612
if (settings.open_at_login) {
613613
base::string16 exe = settings.path;

shell/browser/electron_browser_context.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void ElectronBrowserContext::InitPrefs() {
228228
auto* current_dictionaries =
229229
prefs()->Get(spellcheck::prefs::kSpellCheckDictionaries);
230230
// No configured dictionaries, the default will be en-US
231-
if (current_dictionaries->GetList().size() == 0) {
231+
if (current_dictionaries->GetList().empty()) {
232232
std::string default_code = spellcheck::GetCorrespondingSpellCheckLanguage(
233233
base::i18n::GetConfiguredLocale());
234234
if (!default_code.empty()) {

shell/browser/electron_download_manager_delegate.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void ElectronDownloadManagerDelegate::OnDownloadPathGenerated(
107107

108108
if (!settings.parent_window)
109109
settings.parent_window = window;
110-
if (settings.title.size() == 0)
110+
if (settings.title.empty())
111111
settings.title = item->GetURL().spec();
112112
if (settings.default_path.empty())
113113
settings.default_path = default_path;

shell/browser/native_window_views_win.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ void NativeWindowViews::SetForwardMouseMessages(bool forward) {
384384

385385
RemoveWindowSubclass(legacy_window_, SubclassProc, 1);
386386

387-
if (forwarding_windows_.size() == 0) {
387+
if (forwarding_windows_.empty()) {
388388
UnhookWindowsHookEx(mouse_hook_);
389389
mouse_hook_ = NULL;
390390
}

shell/browser/osr/osr_render_widget_host_view.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ void OffScreenRenderWidgetHostView::CompositeFrame(
683683
SkBitmap frame;
684684

685685
// Optimize for the case when there is no popup
686-
if (proxy_views_.size() == 0 && !popup_host_view_) {
686+
if (proxy_views_.empty() && !popup_host_view_) {
687687
frame = GetBacking();
688688
} else {
689689
frame.allocN32Pixels(size_in_pixels.width(), size_in_pixels.height(),

shell/browser/ui/autofill_popup.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ int AutofillPopup::GetDesiredPopupWidth() {
148148
kEndPadding + 2 * kPopupBorderThickness +
149149
gfx::GetStringWidth(GetValueAt(i), GetValueFontListForRow(i)) +
150150
gfx::GetStringWidth(GetLabelAt(i), GetLabelFontListForRow(i));
151-
if (GetLabelAt(i).length() > 0)
151+
if (!GetLabelAt(i).empty())
152152
row_size += kNamePadding + kEndPadding;
153153

154154
popup_width = std::max(popup_width, row_size);

shell/browser/ui/message_box_win.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ DialogResult ShowTaskDialogUTF16(NativeWindow* parent,
161161
} else {
162162
MapToCommonID(buttons, &id_map, &config.dwCommonButtons, &dialog_buttons);
163163
}
164-
if (dialog_buttons.size() > 0) {
164+
if (!dialog_buttons.empty()) {
165165
config.pButtons = &dialog_buttons.front();
166166
config.cButtons = dialog_buttons.size();
167167
if (!no_link)

shell/common/gin_converters/guid_converter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct Converter<UUID> {
3737

3838
UUID uid;
3939

40-
if (guid.length() > 0) {
40+
if (!guid.empty()) {
4141
if (guid[0] == '{' && guid[guid.length() - 1] == '}') {
4242
guid = guid.substr(1, guid.length() - 2);
4343
}

shell/renderer/api/electron_api_context_bridge.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ void OverrideGlobalValueFromIsolatedWorld(
564564
const std::vector<std::string>& key_path,
565565
v8::Local<v8::Object> value,
566566
bool support_dynamic_properties) {
567-
if (key_path.size() == 0)
567+
if (key_path.empty())
568568
return;
569569

570570
auto* render_frame = GetRenderFrame(value);
@@ -596,7 +596,7 @@ bool OverrideGlobalPropertyFromIsolatedWorld(
596596
v8::Local<v8::Object> getter,
597597
v8::Local<v8::Value> setter,
598598
gin_helper::Arguments* args) {
599-
if (key_path.size() == 0)
599+
if (key_path.empty())
600600
return false;
601601

602602
auto* render_frame = GetRenderFrame(getter);

0 commit comments

Comments
 (0)