From b2d2d0053d16ca15c9298f3e8312b494e246c5e9 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 17 Nov 2020 23:48:20 +0000 Subject: No need to copy an empty object into another empty object. --- vespalib/src/vespa/vespalib/trace/trace.cpp | 41 +----------------- vespalib/src/vespa/vespalib/trace/trace.h | 27 ++++++++---- vespalib/src/vespa/vespalib/trace/tracenode.cpp | 56 ++++++++++++------------- vespalib/src/vespa/vespalib/trace/tracenode.h | 6 +-- 4 files changed, 51 insertions(+), 79 deletions(-) (limited to 'vespalib') diff --git a/vespalib/src/vespa/vespalib/trace/trace.cpp b/vespalib/src/vespa/vespalib/trace/trace.cpp index 8ca2ef6561c..2a9afc9b36b 100644 --- a/vespalib/src/vespa/vespalib/trace/trace.cpp +++ b/vespalib/src/vespa/vespalib/trace/trace.cpp @@ -6,45 +6,6 @@ namespace vespalib { -Trace::Trace() : - _level(0), - _root() -{ - // empty -} - -Trace::Trace(uint32_t level) : - _level(level), - _root() -{ - // empty -} - -Trace::~Trace() = default; - -Trace & -Trace::clear() -{ - _level = 0; - _root.clear(); - return *this; -} - -Trace & -Trace::swap(Trace &other) -{ - std::swap(_level, other._level); - _root.swap(other._root); - return *this; -} - -Trace & -Trace::setLevel(uint32_t level) -{ - _level = std::min(level, 9u); - return *this; -} - bool Trace::trace(uint32_t level, const string ¬e, bool addTime) { @@ -53,7 +14,7 @@ Trace::trace(uint32_t level, const string ¬e, bool addTime) } if (addTime) { struct timeval tv; - gettimeofday(&tv, NULL); + gettimeofday(&tv, nullptr); _root.addChild(make_string("[%ld.%06ld] %s", tv.tv_sec, static_cast(tv.tv_usec), note.c_str())); } else { _root.addChild(note); diff --git a/vespalib/src/vespa/vespalib/trace/trace.h b/vespalib/src/vespa/vespalib/trace/trace.h index d1ca5c5d7e7..6676be4a81e 100644 --- a/vespalib/src/vespa/vespalib/trace/trace.h +++ b/vespalib/src/vespa/vespalib/trace/trace.h @@ -19,30 +19,32 @@ namespace vespalib { */ class Trace { private: - uint32_t _level; TraceNode _root; - + uint32_t _level; public: /** * Create an empty Trace with level set to 0 (no tracing) */ - Trace(); - ~Trace(); + Trace() : Trace(0) {} /** * Create an empty trace with given level. * * @param level Level to set. */ - explicit Trace(uint32_t level); + explicit Trace(uint32_t level) : _root(), _level(level) { } /** * Remove all trace information and set the trace level to 0. * * @return This, to allow chaining. */ - Trace &clear(); + Trace &clear() { + _level = 0; + _root.clear(); + return *this; + } /** * Swap the internals of this with another. @@ -50,7 +52,11 @@ public: * @param other The trace to swap internals with. * @return This, to allow chaining. */ - Trace &swap(Trace &other); + Trace &swap(Trace &other) { + std::swap(_level, other._level); + _root.swap(other._root); + return *this; + } /** * Set the trace level. 0 means no tracing, 9 means enable all tracing. @@ -58,7 +64,10 @@ public: * @param level The level to set. * @return This, to allow chaining. */ - Trace &setLevel(uint32_t level); + Trace &setLevel(uint32_t level) { + _level = std::min(level, 9u); + return *this; + } /** * Returns the trace level. @@ -105,6 +114,8 @@ public: */ const TraceNode &getRoot() const { return _root; } + bool isEmpty() const { return _root.isEmpty(); } + /** * Returns a string representation of the contained trace tree. This is a * readable, non-parseable string. diff --git a/vespalib/src/vespa/vespalib/trace/tracenode.cpp b/vespalib/src/vespa/vespalib/trace/tracenode.cpp index d34b45025d3..0f845ca646a 100644 --- a/vespalib/src/vespa/vespalib/trace/tracenode.cpp +++ b/vespalib/src/vespa/vespalib/trace/tracenode.cpp @@ -40,22 +40,22 @@ struct Cmp { } // namespace -TraceNode::TraceNode() : - _parent(nullptr), - _strict(true), - _hasNote(false), - _note(""), - _children(), - _timestamp() +TraceNode::TraceNode() + : _note(""), + _children(), + _parent(nullptr), + _timestamp(), + _strict(true), + _hasNote(false) { } -TraceNode::TraceNode(const TraceNode &rhs) : - _parent(nullptr), - _strict(rhs._strict), - _hasNote(rhs._hasNote), - _note(rhs._note), - _children(), - _timestamp(rhs._timestamp) +TraceNode::TraceNode(const TraceNode &rhs) + : _note(rhs._note), + _children(), + _parent(nullptr), + _timestamp(rhs._timestamp), + _strict(rhs._strict), + _hasNote(rhs._hasNote) { addChildren(rhs._children); } @@ -65,22 +65,22 @@ TraceNode & TraceNode::operator =(const TraceNode &) = default; TraceNode::~TraceNode() = default; -TraceNode::TraceNode(const string ¬e, system_time timestamp) : - _parent(nullptr), - _strict(true), - _hasNote(true), - _note(note), - _children(), - _timestamp(timestamp) +TraceNode::TraceNode(const string ¬e, system_time timestamp) + : _note(note), + _children(), + _parent(nullptr), + _timestamp(timestamp), + _strict(true), + _hasNote(true) { } -TraceNode::TraceNode(system_time timestamp) : - _parent(nullptr), - _strict(true), - _hasNote(false), - _note(""), - _children(), - _timestamp(timestamp) +TraceNode::TraceNode(system_time timestamp) + : _note(""), + _children(), + _parent(nullptr), + _timestamp(timestamp), + _strict(true), + _hasNote(false) { } TraceNode & diff --git a/vespalib/src/vespa/vespalib/trace/tracenode.h b/vespalib/src/vespa/vespalib/trace/tracenode.h index 63e7bcd6dc0..405c7d994da 100644 --- a/vespalib/src/vespa/vespalib/trace/tracenode.h +++ b/vespalib/src/vespa/vespalib/trace/tracenode.h @@ -23,12 +23,12 @@ struct TraceVisitor; */ class TraceNode { private: - TraceNode *_parent; - bool _strict; - bool _hasNote; string _note; std::vector _children; + TraceNode *_parent; system_time _timestamp; + bool _strict; + bool _hasNote; public: /** -- cgit v1.2.3