[clang-tidy] use references where appropriate
Found with performance-move-const-arg Found with performance-unnecessary-value-param Found with modernize-pass-by-value Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
parent
b4aa8554ad
commit
7a07ef4d21
@ -37,6 +37,7 @@ THE SOFTWARE.
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifdef __cpp_lib_optional
|
#ifdef __cpp_lib_optional
|
||||||
@ -227,9 +228,9 @@ namespace cxxopts
|
|||||||
|
|
||||||
inline
|
inline
|
||||||
String&
|
String&
|
||||||
stringAppend(String&s, String a)
|
stringAppend(String&s, const String& a)
|
||||||
{
|
{
|
||||||
return s.append(std::move(a));
|
return s.append(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@ -324,8 +325,8 @@ namespace cxxopts
|
|||||||
class OptionException : public std::exception
|
class OptionException : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OptionException(const std::string& message)
|
OptionException(std::string message)
|
||||||
: m_message(message)
|
: m_message(std::move(message))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -985,15 +986,15 @@ namespace cxxopts
|
|||||||
public:
|
public:
|
||||||
OptionDetails
|
OptionDetails
|
||||||
(
|
(
|
||||||
const std::string& short_,
|
std::string short_,
|
||||||
const std::string& long_,
|
std::string long_,
|
||||||
const String& desc,
|
String desc,
|
||||||
std::shared_ptr<const Value> val
|
std::shared_ptr<const Value> val
|
||||||
)
|
)
|
||||||
: m_short(short_)
|
: m_short(std::move(short_))
|
||||||
, m_long(long_)
|
, m_long(std::move(long_))
|
||||||
, m_desc(desc)
|
, m_desc(std::move(desc))
|
||||||
, m_value(val)
|
, m_value(std::move(val))
|
||||||
, m_count(0)
|
, m_count(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -1070,7 +1071,7 @@ namespace cxxopts
|
|||||||
void
|
void
|
||||||
parse
|
parse
|
||||||
(
|
(
|
||||||
std::shared_ptr<const OptionDetails> details,
|
const std::shared_ptr<const OptionDetails>& details,
|
||||||
const std::string& text
|
const std::string& text
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -1080,7 +1081,7 @@ namespace cxxopts
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
parse_default(std::shared_ptr<const OptionDetails> details)
|
parse_default(const std::shared_ptr<const OptionDetails>& details)
|
||||||
{
|
{
|
||||||
ensure_value(details);
|
ensure_value(details);
|
||||||
m_default = true;
|
m_default = true;
|
||||||
@ -1117,7 +1118,7 @@ namespace cxxopts
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void
|
void
|
||||||
ensure_value(std::shared_ptr<const OptionDetails> details)
|
ensure_value(const std::shared_ptr<const OptionDetails>& details)
|
||||||
{
|
{
|
||||||
if (m_value == nullptr)
|
if (m_value == nullptr)
|
||||||
{
|
{
|
||||||
@ -1172,7 +1173,7 @@ namespace cxxopts
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
ParseResult(
|
ParseResult(
|
||||||
const std::shared_ptr<
|
std::shared_ptr<
|
||||||
std::unordered_map<std::string, std::shared_ptr<OptionDetails>>
|
std::unordered_map<std::string, std::shared_ptr<OptionDetails>>
|
||||||
>,
|
>,
|
||||||
std::vector<std::string>,
|
std::vector<std::string>,
|
||||||
@ -1223,18 +1224,18 @@ namespace cxxopts
|
|||||||
add_to_option(const std::string& option, const std::string& arg);
|
add_to_option(const std::string& option, const std::string& arg);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
consume_positional(std::string a);
|
consume_positional(const std::string& a);
|
||||||
|
|
||||||
void
|
void
|
||||||
parse_option
|
parse_option
|
||||||
(
|
(
|
||||||
std::shared_ptr<OptionDetails> value,
|
const std::shared_ptr<OptionDetails>& value,
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
const std::string& arg = ""
|
const std::string& arg = ""
|
||||||
);
|
);
|
||||||
|
|
||||||
void
|
void
|
||||||
parse_default(std::shared_ptr<OptionDetails> details);
|
parse_default(const std::shared_ptr<OptionDetails>& details);
|
||||||
|
|
||||||
void
|
void
|
||||||
checked_parse_arg
|
checked_parse_arg
|
||||||
@ -1242,7 +1243,7 @@ namespace cxxopts
|
|||||||
int argc,
|
int argc,
|
||||||
char* argv[],
|
char* argv[],
|
||||||
int& current,
|
int& current,
|
||||||
std::shared_ptr<OptionDetails> value,
|
const std::shared_ptr<OptionDetails>& value,
|
||||||
const std::string& name
|
const std::string& name
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1263,15 +1264,15 @@ namespace cxxopts
|
|||||||
{
|
{
|
||||||
Option
|
Option
|
||||||
(
|
(
|
||||||
const std::string& opts,
|
std::string opts,
|
||||||
const std::string& desc,
|
std::string desc,
|
||||||
const std::shared_ptr<const Value>& value = ::cxxopts::value<bool>(),
|
std::shared_ptr<const Value> value = ::cxxopts::value<bool>(),
|
||||||
const std::string& arg_help = ""
|
std::string arg_help = ""
|
||||||
)
|
)
|
||||||
: opts_(opts)
|
: opts_(std::move(opts))
|
||||||
, desc_(desc)
|
, desc_(std::move(desc))
|
||||||
, value_(value)
|
, value_(std::move(value))
|
||||||
, arg_help_(arg_help)
|
, arg_help_(std::move(arg_help))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1353,7 +1354,7 @@ namespace cxxopts
|
|||||||
const std::string& s,
|
const std::string& s,
|
||||||
const std::string& l,
|
const std::string& l,
|
||||||
std::string desc,
|
std::string desc,
|
||||||
std::shared_ptr<const Value> value,
|
const std::shared_ptr<const Value>& value,
|
||||||
std::string arg_help
|
std::string arg_help
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1388,7 +1389,7 @@ namespace cxxopts
|
|||||||
add_one_option
|
add_one_option
|
||||||
(
|
(
|
||||||
const std::string& option,
|
const std::string& option,
|
||||||
std::shared_ptr<OptionDetails> details
|
const std::shared_ptr<OptionDetails>& details
|
||||||
);
|
);
|
||||||
|
|
||||||
String
|
String
|
||||||
@ -1434,7 +1435,7 @@ namespace cxxopts
|
|||||||
(
|
(
|
||||||
const std::string& opts,
|
const std::string& opts,
|
||||||
const std::string& desc,
|
const std::string& desc,
|
||||||
std::shared_ptr<const Value> value
|
const std::shared_ptr<const Value>& value
|
||||||
= ::cxxopts::value<bool>(),
|
= ::cxxopts::value<bool>(),
|
||||||
std::string arg_help = ""
|
std::string arg_help = ""
|
||||||
);
|
);
|
||||||
@ -1577,14 +1578,14 @@ namespace cxxopts
|
|||||||
inline
|
inline
|
||||||
ParseResult::ParseResult
|
ParseResult::ParseResult
|
||||||
(
|
(
|
||||||
const std::shared_ptr<
|
std::shared_ptr<
|
||||||
std::unordered_map<std::string, std::shared_ptr<OptionDetails>>
|
std::unordered_map<std::string, std::shared_ptr<OptionDetails>>
|
||||||
> options,
|
> options,
|
||||||
std::vector<std::string> positional,
|
std::vector<std::string> positional,
|
||||||
bool allow_unrecognised,
|
bool allow_unrecognised,
|
||||||
int& argc, char**& argv
|
int& argc, char**& argv
|
||||||
)
|
)
|
||||||
: m_options(options)
|
: m_options(std::move(options))
|
||||||
, m_positional(std::move(positional))
|
, m_positional(std::move(positional))
|
||||||
, m_next_positional(m_positional.begin())
|
, m_next_positional(m_positional.begin())
|
||||||
, m_allow_unrecognised(allow_unrecognised)
|
, m_allow_unrecognised(allow_unrecognised)
|
||||||
@ -1620,7 +1621,7 @@ OptionAdder::operator()
|
|||||||
(
|
(
|
||||||
const std::string& opts,
|
const std::string& opts,
|
||||||
const std::string& desc,
|
const std::string& desc,
|
||||||
std::shared_ptr<const Value> value,
|
const std::shared_ptr<const Value>& value,
|
||||||
std::string arg_help
|
std::string arg_help
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -1671,7 +1672,7 @@ OptionAdder::operator()
|
|||||||
|
|
||||||
inline
|
inline
|
||||||
void
|
void
|
||||||
ParseResult::parse_default(std::shared_ptr<OptionDetails> details)
|
ParseResult::parse_default(const std::shared_ptr<OptionDetails>& details)
|
||||||
{
|
{
|
||||||
m_results[details].parse_default(details);
|
m_results[details].parse_default(details);
|
||||||
}
|
}
|
||||||
@ -1680,7 +1681,7 @@ inline
|
|||||||
void
|
void
|
||||||
ParseResult::parse_option
|
ParseResult::parse_option
|
||||||
(
|
(
|
||||||
std::shared_ptr<OptionDetails> value,
|
const std::shared_ptr<OptionDetails>& value,
|
||||||
const std::string& /*name*/,
|
const std::string& /*name*/,
|
||||||
const std::string& arg
|
const std::string& arg
|
||||||
)
|
)
|
||||||
@ -1698,7 +1699,7 @@ ParseResult::checked_parse_arg
|
|||||||
int argc,
|
int argc,
|
||||||
char* argv[],
|
char* argv[],
|
||||||
int& current,
|
int& current,
|
||||||
std::shared_ptr<OptionDetails> value,
|
const std::shared_ptr<OptionDetails>& value,
|
||||||
const std::string& name
|
const std::string& name
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -1743,7 +1744,7 @@ ParseResult::add_to_option(const std::string& option, const std::string& arg)
|
|||||||
|
|
||||||
inline
|
inline
|
||||||
bool
|
bool
|
||||||
ParseResult::consume_positional(std::string a)
|
ParseResult::consume_positional(const std::string& a)
|
||||||
{
|
{
|
||||||
while (m_next_positional != m_positional.end())
|
while (m_next_positional != m_positional.end())
|
||||||
{
|
{
|
||||||
@ -1792,7 +1793,7 @@ inline
|
|||||||
void
|
void
|
||||||
Options::parse_positional(std::initializer_list<std::string> options)
|
Options::parse_positional(std::initializer_list<std::string> options)
|
||||||
{
|
{
|
||||||
parse_positional(std::vector<std::string>(std::move(options)));
|
parse_positional(std::vector<std::string>(options));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@ -1982,7 +1983,7 @@ Options::add_option
|
|||||||
const std::string& s,
|
const std::string& s,
|
||||||
const std::string& l,
|
const std::string& l,
|
||||||
std::string desc,
|
std::string desc,
|
||||||
std::shared_ptr<const Value> value,
|
const std::shared_ptr<const Value>& value,
|
||||||
std::string arg_help
|
std::string arg_help
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -2015,7 +2016,7 @@ void
|
|||||||
Options::add_one_option
|
Options::add_one_option
|
||||||
(
|
(
|
||||||
const std::string& option,
|
const std::string& option,
|
||||||
std::shared_ptr<OptionDetails> details
|
const std::shared_ptr<OptionDetails>& details
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
auto in = m_options->emplace(option, details);
|
auto in = m_options->emplace(option, details);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user