Browse Source

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

David Sanders 3 years ago
parent
commit
9bb7051f54

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

@@ -177,7 +177,7 @@ std::vector<blink::MessagePortChannel> MessagePort::DisentanglePorts(
     v8::Isolate* isolate,
     const std::vector<gin::Handle<MessagePort>>& ports,
     bool* threw_exception) {
-  if (!ports.size())
+  if (ports.empty())
     return std::vector<blink::MessagePortChannel>();
 
   std::unordered_set<MessagePort*> visited;

+ 1 - 1
shell/browser/extensions/electron_extension_loader.cc

@@ -54,7 +54,7 @@ std::pair<scoped_refptr<const Extension>, std::string> LoadUnpacked(
 
   std::string warnings;
   // Log warnings.
-  if (extension->install_warnings().size()) {
+  if (!extension->install_warnings().empty()) {
     warnings += "Warnings loading extension at " +
                 base::UTF16ToUTF8(extension_dir.LossyDisplayName()) + ":\n";
     for (const auto& warning : extension->install_warnings()) {

+ 1 - 2
shell/browser/file_select_helper.cc

@@ -162,8 +162,7 @@ void FileSelectHelper::OnOpenDialogDone(gin_helper::Dictionary result) {
       std::vector<ui::SelectedFileInfo> files =
           ui::FilePathListToSelectedFileInfoList(paths);
       // If we are uploading a folder we need to enumerate its contents
-      if (mode_ == FileChooserParams::Mode::kUploadFolder &&
-          paths.size() >= 1) {
+      if (mode_ == FileChooserParams::Mode::kUploadFolder && !paths.empty()) {
         lister_base_dir_ = paths[0];
         EnumerateDirectory();
       } else {

+ 2 - 2
shell/common/asar/archive.cc

@@ -58,7 +58,7 @@ bool GetChildNode(const base::DictionaryValue* root,
                   const std::string& name,
                   const base::DictionaryValue* dir,
                   const base::DictionaryValue** out) {
-  if (name == "") {
+  if (name.empty()) {
     *out = root;
     return true;
   }
@@ -72,7 +72,7 @@ bool GetChildNode(const base::DictionaryValue* root,
 bool GetNodeFromPath(std::string path,
                      const base::DictionaryValue* root,
                      const base::DictionaryValue** out) {
-  if (path == "") {
+  if (path.empty()) {
     *out = root;
     return true;
   }