From 0d5fc82245352eb6ed4cf11d85a508a8a03e23bb Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 22 Jul 2020 13:33:03 -0700 Subject: [PATCH] [lldb] Eliminate unneeded value parameters in Utility (NFC) Eliminates value parameter for types that are not trivially copyable. --- lldb/include/lldb/Utility/ArchSpec.h | 2 +- lldb/include/lldb/Utility/Broadcaster.h | 4 ++-- lldb/include/lldb/Utility/ConstString.h | 25 +++++++++++++------------ lldb/include/lldb/Utility/RegisterValue.h | 7 ++++--- lldb/include/lldb/Utility/Reproducer.h | 3 ++- lldb/include/lldb/Utility/Scalar.h | 5 +++-- lldb/include/lldb/Utility/StringList.h | 2 +- lldb/include/lldb/Utility/StructuredData.h | 8 ++++---- lldb/include/lldb/Utility/XcodeSDK.h | 6 +++--- lldb/source/Utility/ArchSpec.cpp | 2 +- lldb/source/Utility/ConstString.cpp | 10 +++++----- lldb/source/Utility/Reproducer.cpp | 2 +- lldb/source/Utility/Scalar.cpp | 2 +- lldb/source/Utility/StringLexer.cpp | 3 ++- lldb/source/Utility/StringList.cpp | 2 +- lldb/source/Utility/StructuredData.cpp | 3 ++- lldb/source/Utility/XcodeSDK.cpp | 6 +++--- 17 files changed, 49 insertions(+), 43 deletions(-) diff --git a/lldb/include/lldb/Utility/ArchSpec.h b/lldb/include/lldb/Utility/ArchSpec.h index 5466e57..a727d5c 100644 --- a/lldb/include/lldb/Utility/ArchSpec.h +++ b/lldb/include/lldb/Utility/ArchSpec.h @@ -505,7 +505,7 @@ public: 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 0399545..9c025a7 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 @@ private: 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 1e55b2e..459e6dc 100644 --- a/lldb/include/lldb/Utility/ConstString.h +++ b/lldb/include/lldb/Utility/ConstString.h @@ -133,7 +133,7 @@ public: /// /// \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 @@ public: /// \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 @@ public: /// \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 @@ public: /// \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 @@ public: /// 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 @@ public: /// 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 @@ public: /// 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 @@ protected: }; /// 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 { return lldb_private::ConstString::FromStringPoolPointer( DenseMapInfo::getTombstoneKey()); } - static unsigned getHashValue(lldb_private::ConstString val) { + static unsigned getHashValue(const lldb_private::ConstString &val) { return DenseMapInfo::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 { }; } // 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 c9f295a..4885d58 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 #include +#include namespace lldb_private { class DataExtractor; @@ -60,7 +61,7 @@ public: } 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 @@ public: 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 @@ public: 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 b3d4707..21f43b6 100644 --- a/lldb/include/lldb/Utility/Reproducer.h +++ b/lldb/include/lldb/Utility/Reproducer.h @@ -18,6 +18,7 @@ #include #include +#include #include namespace lldb_private { @@ -435,7 +436,7 @@ private: /// return the path to the files in the index. template class MultiLoader { public: - MultiLoader(std::vector files) : m_files(files) {} + MultiLoader(std::vector files) : m_files(std::move(files)) {} static std::unique_ptr Create(Loader *loader) { if (!loader) diff --git a/lldb/include/lldb/Utility/Scalar.h b/lldb/include/lldb/Utility/Scalar.h index 0bb5c7d..524b715 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 #include +#include namespace lldb_private { class DataExtractor; @@ -89,7 +90,7 @@ public: llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, (reinterpret_cast(&v))->x)) {} Scalar(llvm::APInt v) : m_type(), m_float(static_cast(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 591a158..34930ab 100644 --- a/lldb/include/lldb/Utility/StringList.h +++ b/lldb/include/lldb/Utility/StringList.h @@ -102,7 +102,7 @@ public: 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 &rhs); diff --git a/lldb/include/lldb/Utility/StructuredData.h b/lldb/include/lldb/Utility/StructuredData.h index 14c82e6..4d03af1 100644 --- a/lldb/include/lldb/Utility/StructuredData.h +++ b/lldb/include/lldb/Utility/StructuredData.h @@ -271,9 +271,9 @@ public: 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 @@ public: 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 @@ public: 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 307fe7f..878b131 100644 --- a/lldb/include/lldb/Utility/XcodeSDK.h +++ b/lldb/include/lldb/Utility/XcodeSDK.h @@ -65,11 +65,11 @@ public: /// 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 ca1ce4b..f220f4e 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 62f79b3..2a9272c 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 3ad1064..4441f3d 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 e2c1f37..27d5b3b 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 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 947472a..2618551 100644 --- a/lldb/source/Utility/StringLexer.cpp +++ b/lldb/source/Utility/StringLexer.cpp @@ -10,10 +10,11 @@ #include #include +#include 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 809c5a0..d3896ca 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 df1b356..359c49a 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 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 066bf45..4f64042 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(); -- 2.7.4