mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-27 11:21:02 +08:00
PERF: Allow compiler to choose best way to construct a copy
With move semantics added to the language and the standard library updated with move constructors added for many types it is now interesting to take an argument directly by value, instead of by const-reference, and then copy. This check allows the compiler to take care of choosing the best way to construct the copy. The transformation is usually beneficial when the calling code passes an rvalue and assumes the move construction is a cheap operation. This short example illustrates how the construction of the value happens: SRCDIR=/Users/johnsonhj/src/jsoncpp/ #My local SRC BLDDIR=/Users/johnsonhj/src/jsoncpp/cmake-build-debug/ #My local BLD cd /Users/johnsonhj/src/jsoncpp/cmake-build-debug/ run-clang-tidy.py -extra-arg=-D__clang__ -checks=-*,modernize-pass-by-value -header-filter=.* -fix
This commit is contained in:
parent
1fc3de7ca1
commit
b5093e8122
@ -54,7 +54,7 @@ namespace Json {
|
|||||||
*/
|
*/
|
||||||
class JSON_API Exception : public std::exception {
|
class JSON_API Exception : public std::exception {
|
||||||
public:
|
public:
|
||||||
Exception(JSONCPP_STRING const& msg);
|
Exception(JSONCPP_STRING msg);
|
||||||
~Exception() JSONCPP_NOEXCEPT override;
|
~Exception() JSONCPP_NOEXCEPT override;
|
||||||
char const* what() const JSONCPP_NOEXCEPT override;
|
char const* what() const JSONCPP_NOEXCEPT override;
|
||||||
|
|
||||||
|
@ -300,8 +300,8 @@ public:
|
|||||||
/**
|
/**
|
||||||
* \param indentation Each level will be indented by this amount extra.
|
* \param indentation Each level will be indented by this amount extra.
|
||||||
*/
|
*/
|
||||||
StyledStreamWriter(const JSONCPP_STRING& indentation = "\t");
|
StyledStreamWriter(JSONCPP_STRING indentation = "\t");
|
||||||
~StyledStreamWriter() {}
|
~StyledStreamWriter() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
|
/** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
|
||||||
|
@ -88,9 +88,8 @@ bool Reader::containsNewLine(Reader::Location begin, Reader::Location end) {
|
|||||||
// //////////////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Reader::Reader()
|
Reader::Reader()
|
||||||
: errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
|
: errors_(), document_(), commentsBefore_(), features_(Features::all())
|
||||||
lastValue_(), commentsBefore_(), features_(Features::all()),
|
{}
|
||||||
collectComments_() {}
|
|
||||||
|
|
||||||
Reader::Reader(const Features& features)
|
Reader::Reader(const Features& features)
|
||||||
: errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
|
: errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
|
||||||
|
@ -213,7 +213,7 @@ static inline void releaseStringValue(char* value, unsigned) { free(value); }
|
|||||||
|
|
||||||
namespace Json {
|
namespace Json {
|
||||||
|
|
||||||
Exception::Exception(JSONCPP_STRING const& msg) : msg_(msg) {}
|
Exception::Exception(JSONCPP_STRING msg) : msg_(std::move(msg)) {}
|
||||||
Exception::~Exception() JSONCPP_NOEXCEPT {}
|
Exception::~Exception() JSONCPP_NOEXCEPT {}
|
||||||
char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); }
|
char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); }
|
||||||
RuntimeError::RuntimeError(JSONCPP_STRING const& msg) : Exception(msg) {}
|
RuntimeError::RuntimeError(JSONCPP_STRING const& msg) : Exception(msg) {}
|
||||||
|
@ -642,8 +642,8 @@ bool StyledWriter::hasCommentForValue(const Value& value) {
|
|||||||
// Class StyledStreamWriter
|
// Class StyledStreamWriter
|
||||||
// //////////////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
StyledStreamWriter::StyledStreamWriter(const JSONCPP_STRING& indentation)
|
StyledStreamWriter::StyledStreamWriter(JSONCPP_STRING indentation)
|
||||||
: document_(nullptr), rightMargin_(74), indentation_(indentation),
|
: document_(nullptr), indentation_(std::move(indentation)),
|
||||||
addChildValues_(), indented_(false) {}
|
addChildValues_(), indented_(false) {}
|
||||||
|
|
||||||
void StyledStreamWriter::write(JSONCPP_OSTREAM& out, const Value& root) {
|
void StyledStreamWriter::write(JSONCPP_OSTREAM& out, const Value& root) {
|
||||||
@ -872,11 +872,11 @@ struct CommentStyle {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct BuiltStyledStreamWriter : public StreamWriter {
|
struct BuiltStyledStreamWriter : public StreamWriter {
|
||||||
BuiltStyledStreamWriter(JSONCPP_STRING const& indentation,
|
BuiltStyledStreamWriter(JSONCPP_STRING indentation,
|
||||||
CommentStyle::Enum cs,
|
CommentStyle::Enum cs,
|
||||||
JSONCPP_STRING const& colonSymbol,
|
JSONCPP_STRING colonSymbol,
|
||||||
JSONCPP_STRING const& nullSymbol,
|
JSONCPP_STRING nullSymbol,
|
||||||
JSONCPP_STRING const& endingLineFeedSymbol,
|
JSONCPP_STRING endingLineFeedSymbol,
|
||||||
bool useSpecialFloats,
|
bool useSpecialFloats,
|
||||||
unsigned int precision,
|
unsigned int precision,
|
||||||
PrecisionType precisionType);
|
PrecisionType precisionType);
|
||||||
@ -912,17 +912,17 @@ private:
|
|||||||
PrecisionType precisionType_;
|
PrecisionType precisionType_;
|
||||||
};
|
};
|
||||||
BuiltStyledStreamWriter::BuiltStyledStreamWriter(
|
BuiltStyledStreamWriter::BuiltStyledStreamWriter(
|
||||||
JSONCPP_STRING const& indentation,
|
JSONCPP_STRING indentation,
|
||||||
CommentStyle::Enum cs,
|
CommentStyle::Enum cs,
|
||||||
JSONCPP_STRING const& colonSymbol,
|
JSONCPP_STRING colonSymbol,
|
||||||
JSONCPP_STRING const& nullSymbol,
|
JSONCPP_STRING nullSymbol,
|
||||||
JSONCPP_STRING const& endingLineFeedSymbol,
|
JSONCPP_STRING endingLineFeedSymbol,
|
||||||
bool useSpecialFloats,
|
bool useSpecialFloats,
|
||||||
unsigned int precision,
|
unsigned int precision,
|
||||||
PrecisionType precisionType)
|
PrecisionType precisionType)
|
||||||
: rightMargin_(74), indentation_(indentation), cs_(cs),
|
: rightMargin_(74), indentation_(std::move(indentation)), cs_(cs),
|
||||||
colonSymbol_(colonSymbol), nullSymbol_(nullSymbol),
|
colonSymbol_(std::move(colonSymbol)), nullSymbol_(std::move(nullSymbol)),
|
||||||
endingLineFeedSymbol_(endingLineFeedSymbol), addChildValues_(false),
|
endingLineFeedSymbol_(std::move(endingLineFeedSymbol)), addChildValues_(false),
|
||||||
indented_(false), useSpecialFloats_(useSpecialFloats),
|
indented_(false), useSpecialFloats_(useSpecialFloats),
|
||||||
precision_(precision), precisionType_(precisionType) {}
|
precision_(precision), precisionType_(precisionType) {}
|
||||||
int BuiltStyledStreamWriter::write(Value const& root, JSONCPP_OSTREAM* sout) {
|
int BuiltStyledStreamWriter::write(Value const& root, JSONCPP_OSTREAM* sout) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user