Browse Source

chore: prefer empty() check for readability (#26157)

David Sanders 4 years ago
parent
commit
d4112d38de

+ 1 - 1
shell/browser/api/electron_api_base_window.cc

@@ -947,7 +947,7 @@ std::vector<v8::Local<v8::Object>> BaseWindow::GetChildWindows() const {
 
 v8::Local<v8::Value> BaseWindow::GetBrowserView(
     gin_helper::Arguments* args) const {
-  if (browser_views_.size() == 0) {
+  if (browser_views_.empty()) {
     return v8::Null(isolate());
   } else if (browser_views_.size() == 1) {
     auto first_view = browser_views_.begin();

+ 2 - 2
shell/browser/api/electron_api_web_contents.cc

@@ -404,7 +404,7 @@ base::string16 GetDefaultPrinterAsync() {
   if (printer_name.empty()) {
     printing::PrinterList printers;
     print_backend->EnumeratePrinters(&printers);
-    if (printers.size() > 0)
+    if (!printers.empty())
       printer_name = printers.front().printer_name;
   }
   return base::UTF8ToUTF16(printer_name);
@@ -2175,7 +2175,7 @@ void WebContents::Print(gin::Arguments* args) {
         continue;
       }
     }
-    if (page_range_list.GetList().size() > 0)
+    if (!page_range_list.GetList().empty())
       settings.SetPath(printing::kSettingPageRange, std::move(page_range_list));
   }
 

+ 3 - 3
shell/browser/browser_win.cc

@@ -203,7 +203,7 @@ std::vector<Browser::LaunchItem> GetLoginItemSettingsHelper(
       if ((base::CompareCaseInsensitiveASCII(it->Value(), exe.c_str())) == 0) {
         Browser::LaunchItem launch_item;
         base::string16 launch_path = options.path;
-        if (!(launch_path.size() > 0)) {
+        if (launch_path.empty()) {
           GetProcessExecPath(&launch_path);
         }
         launch_item.name = it->Name();
@@ -339,7 +339,7 @@ void GetApplicationInfoForProtocolUsingRegistry(
   }
   const base::string16 app_display_name = GetAppForProtocolUsingRegistry(url);
 
-  if (app_display_name.length() == 0) {
+  if (app_display_name.empty()) {
     promise.RejectWithErrorMessage(
         "Unable to retrieve application display name");
     return;
@@ -607,7 +607,7 @@ void Browser::SetLoginItemSettings(LoginItemSettings settings) {
   base::win::RegKey startup_approved_key(
       HKEY_CURRENT_USER, startup_approved_key_path.c_str(), KEY_ALL_ACCESS);
   PCWSTR key_name =
-      settings.name.size() > 0 ? settings.name.c_str() : GetAppUserModelID();
+      !settings.name.empty() ? settings.name.c_str() : GetAppUserModelID();
 
   if (settings.open_at_login) {
     base::string16 exe = settings.path;

+ 1 - 1
shell/browser/electron_browser_context.cc

@@ -227,7 +227,7 @@ void ElectronBrowserContext::InitPrefs() {
   auto* current_dictionaries =
       prefs()->Get(spellcheck::prefs::kSpellCheckDictionaries);
   // No configured dictionaries, the default will be en-US
-  if (current_dictionaries->GetList().size() == 0) {
+  if (current_dictionaries->GetList().empty()) {
     std::string default_code = spellcheck::GetCorrespondingSpellCheckLanguage(
         base::i18n::GetConfiguredLocale());
     if (!default_code.empty()) {

+ 1 - 1
shell/browser/electron_download_manager_delegate.cc

@@ -107,7 +107,7 @@ void ElectronDownloadManagerDelegate::OnDownloadPathGenerated(
 
     if (!settings.parent_window)
       settings.parent_window = window;
-    if (settings.title.size() == 0)
+    if (settings.title.empty())
       settings.title = item->GetURL().spec();
     if (settings.default_path.empty())
       settings.default_path = default_path;

+ 1 - 1
shell/browser/native_window_views_win.cc

@@ -384,7 +384,7 @@ void NativeWindowViews::SetForwardMouseMessages(bool forward) {
 
     RemoveWindowSubclass(legacy_window_, SubclassProc, 1);
 
-    if (forwarding_windows_.size() == 0) {
+    if (forwarding_windows_.empty()) {
       UnhookWindowsHookEx(mouse_hook_);
       mouse_hook_ = NULL;
     }

+ 1 - 1
shell/browser/osr/osr_render_widget_host_view.cc

@@ -685,7 +685,7 @@ void OffScreenRenderWidgetHostView::CompositeFrame(
   SkBitmap frame;
 
   // Optimize for the case when there is no popup
-  if (proxy_views_.size() == 0 && !popup_host_view_) {
+  if (proxy_views_.empty() && !popup_host_view_) {
     frame = GetBacking();
   } else {
     frame.allocN32Pixels(size_in_pixels.width(), size_in_pixels.height(),

+ 1 - 1
shell/browser/ui/autofill_popup.cc

@@ -148,7 +148,7 @@ int AutofillPopup::GetDesiredPopupWidth() {
         kEndPadding + 2 * kPopupBorderThickness +
         gfx::GetStringWidth(GetValueAt(i), GetValueFontListForRow(i)) +
         gfx::GetStringWidth(GetLabelAt(i), GetLabelFontListForRow(i));
-    if (GetLabelAt(i).length() > 0)
+    if (!GetLabelAt(i).empty())
       row_size += kNamePadding + kEndPadding;
 
     popup_width = std::max(popup_width, row_size);

+ 1 - 1
shell/browser/ui/message_box_win.cc

@@ -161,7 +161,7 @@ DialogResult ShowTaskDialogUTF16(NativeWindow* parent,
   } else {
     MapToCommonID(buttons, &id_map, &config.dwCommonButtons, &dialog_buttons);
   }
-  if (dialog_buttons.size() > 0) {
+  if (!dialog_buttons.empty()) {
     config.pButtons = &dialog_buttons.front();
     config.cButtons = dialog_buttons.size();
     if (!no_link)

+ 1 - 1
shell/common/gin_converters/guid_converter.h

@@ -33,7 +33,7 @@ struct Converter<UUID> {
 
     UUID uid;
 
-    if (guid.length() > 0) {
+    if (!guid.empty()) {
       unsigned char* uid_cstr = (unsigned char*)guid.c_str();
       RPC_STATUS result = UuidFromStringA(uid_cstr, &uid);
       if (result == RPC_S_INVALID_STRING_UUID) {

+ 2 - 2
shell/renderer/api/electron_api_context_bridge.cc

@@ -564,7 +564,7 @@ void OverrideGlobalValueFromIsolatedWorld(
     const std::vector<std::string>& key_path,
     v8::Local<v8::Object> value,
     bool support_dynamic_properties) {
-  if (key_path.size() == 0)
+  if (key_path.empty())
     return;
 
   auto* render_frame = GetRenderFrame(value);
@@ -596,7 +596,7 @@ bool OverrideGlobalPropertyFromIsolatedWorld(
     v8::Local<v8::Object> getter,
     v8::Local<v8::Value> setter,
     gin_helper::Arguments* args) {
-  if (key_path.size() == 0)
+  if (key_path.empty())
     return false;
 
   auto* render_frame = GetRenderFrame(getter);