[Lldb-commits] [lldb] 0d5fc82 - [lldb] Eliminate unneeded value parameters in Utility (NFC)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed Jul 22 13:56:30 PDT 2020


Author: Jonas Devlieghere
Date: 2020-07-22T13:56:23-07:00
New Revision: 0d5fc82245352eb6ed4cf11d85a508a8a03e23bb

URL: https://github.com/llvm/llvm-project/commit/0d5fc82245352eb6ed4cf11d85a508a8a03e23bb
DIFF: https://github.com/llvm/llvm-project/commit/0d5fc82245352eb6ed4cf11d85a508a8a03e23bb.diff

LOG: [lldb] Eliminate unneeded value parameters in Utility (NFC)

Eliminates value parameter for types that are not trivially copyable.

Added: 
    

Modified: 
    lldb/include/lldb/Utility/ArchSpec.h
    lldb/include/lldb/Utility/Broadcaster.h
    lldb/include/lldb/Utility/ConstString.h
    lldb/include/lldb/Utility/RegisterValue.h
    lldb/include/lldb/Utility/Reproducer.h
    lldb/include/lldb/Utility/Scalar.h
    lldb/include/lldb/Utility/StringList.h
    lldb/include/lldb/Utility/StructuredData.h
    lldb/include/lldb/Utility/XcodeSDK.h
    lldb/source/Utility/ArchSpec.cpp
    lldb/source/Utility/ConstString.cpp
    lldb/source/Utility/Reproducer.cpp
    lldb/source/Utility/Scalar.cpp
    lldb/source/Utility/StringLexer.cpp
    lldb/source/Utility/StringList.cpp
    lldb/source/Utility/StructuredData.cpp
    lldb/source/Utility/XcodeSDK.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Utility/ArchSpec.h b/lldb/include/lldb/Utility/ArchSpec.h
index 5466e573c1a5..a727d5ca4f79 100644
--- a/lldb/include/lldb/Utility/ArchSpec.h
+++ b/lldb/include/lldb/Utility/ArchSpec.h
@@ -505,7 +505,7 @@ class ArchSpec {
 
   void SetFlags(uint32_t flags) { m_flags = flags; }
 
-  void SetFlags(std::string elf_abi);
+  void SetFlags(const std::string &elf_abi);
 
 protected:
   bool IsEqualTo(const ArchSpec &rhs, bool exact_match) const;

diff  --git a/lldb/include/lldb/Utility/Broadcaster.h b/lldb/include/lldb/Utility/Broadcaster.h
index 03995454ecb0..9c025a7c7dd8 100644
--- a/lldb/include/lldb/Utility/Broadcaster.h
+++ b/lldb/include/lldb/Utility/Broadcaster.h
@@ -39,7 +39,7 @@ namespace lldb_private {
 /// Debugger maintains a list of BroadcastEventSpec's and when it is made
 class BroadcastEventSpec {
 public:
-  BroadcastEventSpec(ConstString broadcaster_class, uint32_t event_bits)
+  BroadcastEventSpec(const ConstString &broadcaster_class, uint32_t event_bits)
       : m_broadcaster_class(broadcaster_class), m_event_bits(event_bits) {}
 
   ~BroadcastEventSpec() = default;
@@ -117,7 +117,7 @@ class BroadcasterManager
 
   class BroadcasterClassMatches {
   public:
-    BroadcasterClassMatches(ConstString broadcaster_class)
+    BroadcasterClassMatches(const ConstString &broadcaster_class)
         : m_broadcaster_class(broadcaster_class) {}
 
     ~BroadcasterClassMatches() = default;

diff  --git a/lldb/include/lldb/Utility/ConstString.h b/lldb/include/lldb/Utility/ConstString.h
index 1e55b2ebb957..459e6dcc960a 100644
--- a/lldb/include/lldb/Utility/ConstString.h
+++ b/lldb/include/lldb/Utility/ConstString.h
@@ -133,7 +133,7 @@ class ConstString {
   ///
   /// \return
   ///     A const reference to this object.
-  ConstString operator=(ConstString rhs) {
+  ConstString operator=(const ConstString &rhs) {
     m_string = rhs.m_string;
     return *this;
   }
@@ -150,7 +150,7 @@ class ConstString {
   /// \return
   ///     true if this object is equal to \a rhs.
   ///     false if this object is not equal to \a rhs.
-  bool operator==(ConstString rhs) const {
+  bool operator==(const ConstString &rhs) const {
     // We can do a pointer compare to compare these strings since they must
     // come from the same pool in order to be equal.
     return m_string == rhs.m_string;
@@ -192,7 +192,7 @@ class ConstString {
   /// \return
   ///     \b true if this object is not equal to \a rhs.
   ///     \b false if this object is equal to \a rhs.
-  bool operator!=(ConstString rhs) const {
+  bool operator!=(const ConstString &rhs) const {
     return m_string != rhs.m_string;
   }
 
@@ -209,7 +209,7 @@ class ConstString {
   /// \return \b true if this object is not equal to \a rhs, false otherwise.
   bool operator!=(const char *rhs) const { return !(*this == rhs); }
 
-  bool operator<(ConstString rhs) const;
+  bool operator<(const ConstString &rhs) const;
 
   /// Get the string value as a C string.
   ///
@@ -279,7 +279,7 @@ class ConstString {
   ///     will be tested, otherwise character case will be ignored
   ///
   /// \return \b true if this object is equal to \a rhs, \b false otherwise.
-  static bool Equals(ConstString lhs, ConstString rhs,
+  static bool Equals(const ConstString &lhs, const ConstString &rhs,
                      const bool case_sensitive = true);
 
   /// Compare two string objects.
@@ -303,7 +303,7 @@ class ConstString {
   ///     will be performed, otherwise character case will be ignored
   ///
   /// \return -1 if lhs < rhs, 0 if lhs == rhs, 1 if lhs > rhs
-  static int Compare(ConstString lhs, ConstString rhs,
+  static int Compare(const ConstString &lhs, const ConstString &rhs,
                      const bool case_sensitive = true);
 
   /// Dump the object description to a stream.
@@ -371,7 +371,7 @@ class ConstString {
   ///     The already uniqued mangled ConstString to correlate the
   ///     soon to be uniqued version of \a demangled.
   void SetStringWithMangledCounterpart(llvm::StringRef demangled,
-                                       ConstString mangled);
+                                       const ConstString &mangled);
 
   /// Retrieve the mangled or demangled counterpart for a mangled or demangled
   /// ConstString.
@@ -452,7 +452,7 @@ class ConstString {
 };
 
 /// Stream the string value \a str to the stream \a s
-Stream &operator<<(Stream &s, ConstString str);
+Stream &operator<<(Stream &s, const ConstString &str);
 
 } // namespace lldb_private
 
@@ -473,11 +473,11 @@ template <> struct DenseMapInfo<lldb_private::ConstString> {
     return lldb_private::ConstString::FromStringPoolPointer(
         DenseMapInfo<const char *>::getTombstoneKey());
   }
-  static unsigned getHashValue(lldb_private::ConstString val) {
+  static unsigned getHashValue(const lldb_private::ConstString &val) {
     return DenseMapInfo<const char *>::getHashValue(val.m_string);
   }
-  static bool isEqual(lldb_private::ConstString LHS,
-                      lldb_private::ConstString RHS) {
+  static bool isEqual(const lldb_private::ConstString &LHS,
+                      const lldb_private::ConstString &RHS) {
     return LHS == RHS;
   }
 };
@@ -491,7 +491,8 @@ template <> struct ScalarTraits<lldb_private::ConstString> {
 };
 } // namespace yaml
 
-inline raw_ostream &operator<<(raw_ostream &os, lldb_private::ConstString s) {
+inline raw_ostream &operator<<(raw_ostream &os,
+                               const lldb_private::ConstString &s) {
   os << s.GetStringRef();
   return os;
 }

diff  --git a/lldb/include/lldb/Utility/RegisterValue.h b/lldb/include/lldb/Utility/RegisterValue.h
index c9f295a8d95a..4885d5806384 100644
--- a/lldb/include/lldb/Utility/RegisterValue.h
+++ b/lldb/include/lldb/Utility/RegisterValue.h
@@ -18,6 +18,7 @@
 #include "llvm/ADT/StringRef.h"
 #include <cstdint>
 #include <cstring>
+#include <utility>
 
 namespace lldb_private {
 class DataExtractor;
@@ -60,7 +61,7 @@ class RegisterValue {
   }
 
   explicit RegisterValue(llvm::APInt inst) : m_type(eTypeUInt128) {
-    m_scalar = llvm::APInt(inst);
+    m_scalar = llvm::APInt(std::move(inst));
   }
 
   explicit RegisterValue(float value) : m_type(eTypeFloat) { m_scalar = value; }
@@ -169,7 +170,7 @@ class RegisterValue {
 
   void operator=(llvm::APInt uint) {
     m_type = eTypeUInt128;
-    m_scalar = llvm::APInt(uint);
+    m_scalar = llvm::APInt(std::move(uint));
   }
 
   void operator=(float f) {
@@ -209,7 +210,7 @@ class RegisterValue {
 
   void SetUInt128(llvm::APInt uint) {
     m_type = eTypeUInt128;
-    m_scalar = uint;
+    m_scalar = std::move(uint);
   }
 
   bool SetUInt(uint64_t uint, uint32_t byte_size);

diff  --git a/lldb/include/lldb/Utility/Reproducer.h b/lldb/include/lldb/Utility/Reproducer.h
index b3d470702ee5..21f43b6ad5e0 100644
--- a/lldb/include/lldb/Utility/Reproducer.h
+++ b/lldb/include/lldb/Utility/Reproducer.h
@@ -18,6 +18,7 @@
 
 #include <mutex>
 #include <string>
+#include <utility>
 #include <vector>
 
 namespace lldb_private {
@@ -435,7 +436,7 @@ class Reproducer {
 /// return the path to the files in the index.
 template <typename T> class MultiLoader {
 public:
-  MultiLoader(std::vector<std::string> files) : m_files(files) {}
+  MultiLoader(std::vector<std::string> files) : m_files(std::move(files)) {}
 
   static std::unique_ptr<MultiLoader> Create(Loader *loader) {
     if (!loader)

diff  --git a/lldb/include/lldb/Utility/Scalar.h b/lldb/include/lldb/Utility/Scalar.h
index 0bb5c7d1b859..524b71523074 100644
--- a/lldb/include/lldb/Utility/Scalar.h
+++ b/lldb/include/lldb/Utility/Scalar.h
@@ -9,14 +9,15 @@
 #ifndef LLDB_UTILITY_SCALAR_H
 #define LLDB_UTILITY_SCALAR_H
 
+#include "lldb/Utility/LLDBAssert.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-private-types.h"
-#include "lldb/Utility/LLDBAssert.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APInt.h"
 #include <cstddef>
 #include <cstdint>
+#include <utility>
 
 namespace lldb_private {
 class DataExtractor;
@@ -89,7 +90,7 @@ class Scalar {
                 llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
                             (reinterpret_cast<type128 *>(&v))->x)) {}
   Scalar(llvm::APInt v) : m_type(), m_float(static_cast<float>(0)) {
-    m_integer = llvm::APInt(v);
+    m_integer = llvm::APInt(std::move(v));
     m_type = GetBestTypeForBitSize(m_integer.getBitWidth(), true);
   }
   // Scalar(const RegisterValue& reg_value);

diff  --git a/lldb/include/lldb/Utility/StringList.h b/lldb/include/lldb/Utility/StringList.h
index 591a15861593..34930abeac3c 100644
--- a/lldb/include/lldb/Utility/StringList.h
+++ b/lldb/include/lldb/Utility/StringList.h
@@ -102,7 +102,7 @@ class StringList {
 
   StringList &operator<<(const std::string &s);
 
-  StringList &operator<<(StringList strings);
+  StringList &operator<<(const StringList &strings);
 
   // Copy assignment for a vector of strings
   StringList &operator=(const std::vector<std::string> &rhs);

diff  --git a/lldb/include/lldb/Utility/StructuredData.h b/lldb/include/lldb/Utility/StructuredData.h
index 14c82e669676..4d03af18e527 100644
--- a/lldb/include/lldb/Utility/StructuredData.h
+++ b/lldb/include/lldb/Utility/StructuredData.h
@@ -271,9 +271,9 @@ class StructuredData {
       return false;
     }
 
-    void Push(ObjectSP item) { m_items.push_back(item); }
+    void Push(const ObjectSP &item) { m_items.push_back(item); }
 
-    void AddItem(ObjectSP item) { m_items.push_back(item); }
+    void AddItem(const ObjectSP &item) { m_items.push_back(item); }
 
     void Serialize(llvm::json::OStream &s) const override;
 
@@ -493,7 +493,7 @@ class StructuredData {
 
     void AddItem(llvm::StringRef key, ObjectSP value_sp) {
       ConstString key_cs(key);
-      m_dict[key_cs] = value_sp;
+      m_dict[key_cs] = std::move(value_sp);
     }
 
     void AddIntegerItem(llvm::StringRef key, uint64_t value) {
@@ -547,7 +547,7 @@ class StructuredData {
     void *m_object;
   };
 
-  static ObjectSP ParseJSON(std::string json_text);
+  static ObjectSP ParseJSON(const std::string &json_text);
   static ObjectSP ParseJSONFromFile(const FileSpec &file, Status &error);
 };
 

diff  --git a/lldb/include/lldb/Utility/XcodeSDK.h b/lldb/include/lldb/Utility/XcodeSDK.h
index 307fe7f46798..878b131a1814 100644
--- a/lldb/include/lldb/Utility/XcodeSDK.h
+++ b/lldb/include/lldb/Utility/XcodeSDK.h
@@ -65,11 +65,11 @@ class XcodeSDK {
   /// The merge function follows a strict order to maintain monotonicity:
   /// 1. SDK with the higher SDKType wins.
   /// 2. The newer SDK wins.
-  void Merge(XcodeSDK other);
+  void Merge(const XcodeSDK &other);
 
-  XcodeSDK &operator=(XcodeSDK other);
+  XcodeSDK &operator=(const XcodeSDK &other);
   XcodeSDK(const XcodeSDK&) = default;
-  bool operator==(XcodeSDK other);
+  bool operator==(const XcodeSDK &other);
 
   /// Return parsed SDK type and version number.
   Info Parse() const;

diff  --git a/lldb/source/Utility/ArchSpec.cpp b/lldb/source/Utility/ArchSpec.cpp
index ca1ce4b3d378..f220f4e30b29 100644
--- a/lldb/source/Utility/ArchSpec.cpp
+++ b/lldb/source/Utility/ArchSpec.cpp
@@ -613,7 +613,7 @@ std::string ArchSpec::GetTargetABI() const {
   return abi;
 }
 
-void ArchSpec::SetFlags(std::string elf_abi) {
+void ArchSpec::SetFlags(const std::string &elf_abi) {
 
   uint32_t flag = GetFlags();
   if (IsMIPS()) {

diff  --git a/lldb/source/Utility/ConstString.cpp b/lldb/source/Utility/ConstString.cpp
index 62f79b3df7a5..2a9272ce84da 100644
--- a/lldb/source/Utility/ConstString.cpp
+++ b/lldb/source/Utility/ConstString.cpp
@@ -212,7 +212,7 @@ ConstString::ConstString(const char *cstr, size_t cstr_len)
 ConstString::ConstString(const llvm::StringRef &s)
     : m_string(StringPool().GetConstCStringWithStringRef(s)) {}
 
-bool ConstString::operator<(ConstString rhs) const {
+bool ConstString::operator<(const ConstString &rhs) const {
   if (m_string == rhs.m_string)
     return false;
 
@@ -227,7 +227,7 @@ bool ConstString::operator<(ConstString rhs) const {
   return lhs_string_ref.data() == nullptr;
 }
 
-Stream &lldb_private::operator<<(Stream &s, ConstString str) {
+Stream &lldb_private::operator<<(Stream &s, const ConstString &str) {
   const char *cstr = str.GetCString();
   if (cstr != nullptr)
     s << cstr;
@@ -239,7 +239,7 @@ size_t ConstString::GetLength() const {
   return Pool::GetConstCStringLength(m_string);
 }
 
-bool ConstString::Equals(ConstString lhs, ConstString rhs,
+bool ConstString::Equals(const ConstString &lhs, const ConstString &rhs,
                          const bool case_sensitive) {
   if (lhs.m_string == rhs.m_string)
     return true;
@@ -256,7 +256,7 @@ bool ConstString::Equals(ConstString lhs, ConstString rhs,
   return lhs_string_ref.equals_lower(rhs_string_ref);
 }
 
-int ConstString::Compare(ConstString lhs, ConstString rhs,
+int ConstString::Compare(const ConstString &lhs, const ConstString &rhs,
                          const bool case_sensitive) {
   // If the iterators are the same, this is the same string
   const char *lhs_cstr = lhs.m_string;
@@ -308,7 +308,7 @@ void ConstString::SetString(const llvm::StringRef &s) {
 }
 
 void ConstString::SetStringWithMangledCounterpart(llvm::StringRef demangled,
-                                                   ConstString mangled) {
+                                                  const ConstString &mangled) {
   m_string = StringPool().GetConstCStringAndSetMangledCounterPart(
       demangled, mangled.m_string);
 }

diff  --git a/lldb/source/Utility/Reproducer.cpp b/lldb/source/Utility/Reproducer.cpp
index 3ad1064cd4c4..4441f3d475ea 100644
--- a/lldb/source/Utility/Reproducer.cpp
+++ b/lldb/source/Utility/Reproducer.cpp
@@ -157,7 +157,7 @@ FileSpec Reproducer::GetReproducerPath() const {
   return {};
 }
 
-static FileSpec MakeAbsolute(FileSpec file_spec) {
+static FileSpec MakeAbsolute(const FileSpec &file_spec) {
   SmallString<128> path;
   file_spec.GetPath(path, false);
   llvm::sys::fs::make_absolute(path);

diff  --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp
index e2c1f37fe529..27d5b3b88d33 100644
--- a/lldb/source/Utility/Scalar.cpp
+++ b/lldb/source/Utility/Scalar.cpp
@@ -160,7 +160,7 @@ bool Scalar::GetData(DataExtractor &data, size_t limit_byte_size) const {
 void Scalar::GetBytes(llvm::MutableArrayRef<uint8_t> storage) const {
   assert(storage.size() >= GetByteSize());
 
-  const auto &store = [&](const llvm::APInt val) {
+  const auto &store = [&](const llvm::APInt &val) {
     StoreIntToMemory(val, storage.data(), (val.getBitWidth() + 7) / 8);
   };
   switch (GetCategory(m_type)) {

diff  --git a/lldb/source/Utility/StringLexer.cpp b/lldb/source/Utility/StringLexer.cpp
index 947472a014eb..26185517e275 100644
--- a/lldb/source/Utility/StringLexer.cpp
+++ b/lldb/source/Utility/StringLexer.cpp
@@ -10,10 +10,11 @@
 
 #include <algorithm>
 #include <assert.h>
+#include <utility>
 
 using namespace lldb_private;
 
-StringLexer::StringLexer(std::string s) : m_data(s), m_position(0) {}
+StringLexer::StringLexer(std::string s) : m_data(std::move(s)), m_position(0) {}
 
 StringLexer::Character StringLexer::Peek() { return m_data[m_position]; }
 

diff  --git a/lldb/source/Utility/StringList.cpp b/lldb/source/Utility/StringList.cpp
index 809c5a02acf6..d3896ca60ac9 100644
--- a/lldb/source/Utility/StringList.cpp
+++ b/lldb/source/Utility/StringList.cpp
@@ -212,7 +212,7 @@ StringList &StringList::operator<<(const std::string &str) {
   return *this;
 }
 
-StringList &StringList::operator<<(StringList strings) {
+StringList &StringList::operator<<(const StringList &strings) {
   AppendList(strings);
   return *this;
 }

diff  --git a/lldb/source/Utility/StructuredData.cpp b/lldb/source/Utility/StructuredData.cpp
index df1b35618e4a..359c49ae254b 100644
--- a/lldb/source/Utility/StructuredData.cpp
+++ b/lldb/source/Utility/StructuredData.cpp
@@ -21,7 +21,8 @@ static StructuredData::ObjectSP ParseJSONValue(json::Value &value);
 static StructuredData::ObjectSP ParseJSONObject(json::Object *object);
 static StructuredData::ObjectSP ParseJSONArray(json::Array *array);
 
-StructuredData::ObjectSP StructuredData::ParseJSON(std::string json_text) {
+StructuredData::ObjectSP
+StructuredData::ParseJSON(const std::string &json_text) {
   llvm::Expected<json::Value> value = json::parse(json_text);
   if (!value) {
     llvm::consumeError(value.takeError());

diff  --git a/lldb/source/Utility/XcodeSDK.cpp b/lldb/source/Utility/XcodeSDK.cpp
index 066bf457966c..4f64042e3643 100644
--- a/lldb/source/Utility/XcodeSDK.cpp
+++ b/lldb/source/Utility/XcodeSDK.cpp
@@ -54,12 +54,12 @@ XcodeSDK::XcodeSDK(XcodeSDK::Info info) : m_name(GetName(info.type).str()) {
   }
 }
 
-XcodeSDK &XcodeSDK::operator=(XcodeSDK other) {
+XcodeSDK &XcodeSDK::operator=(const XcodeSDK &other) {
   m_name = other.m_name;
   return *this;
 }
 
-bool XcodeSDK::operator==(XcodeSDK other) {
+bool XcodeSDK::operator==(const XcodeSDK &other) {
   return m_name == other.m_name;
 }
 
@@ -147,7 +147,7 @@ bool XcodeSDK::Info::operator==(const Info &other) const {
          std::tie(other.type, other.version, other.internal);
 }
 
-void XcodeSDK::Merge(XcodeSDK other) {
+void XcodeSDK::Merge(const XcodeSDK &other) {
   // The "bigger" SDK always wins.
   auto l = Parse();
   auto r = other.Parse();


        


More information about the lldb-commits mailing list