Commit 56b82d19 authored by EXT Arnaud Clère's avatar EXT Arnaud Clère
Browse files

Avoiding building superfluous Val<> does not seem to pay for the additional...

Avoiding building superfluous Val<> does not seem to pay for the additional friendship declarations on the "user" side.
parent de0052e3
......@@ -149,11 +149,11 @@ public:
Val<TResult> value() { return Val<TResult>(std::move(*static_cast<TResult*>(this))); }
// Shortcuts
/**/ Seq<TResult> sequence() { return value().sequence(); }
/**/ TResult null() { return value(). null(); }
template<typename T> TResult bind(const T& t) { return value(). bind(t); } // TODO only for readers ?
template<typename T> TResult bind( T& t) { return value(). bind(t); }
template<typename T> TResult bind( T&& t) { return value(). bind(t); }
/**/ Seq<TResult> sequence() { /* return value().sequence(); */ if (Q_LIKELY(m) && m->_sequence()) return Seq<TResult>(std::move(*static_cast<TResult*>(this))); return Seq<TResult>(); }
/**/ TResult null() { /* return value(). null(); */ if (Q_LIKELY(m) && m-> _null()) return std::move(*static_cast<TResult*>(this)) ; return TResult (); }
template<typename T> TResult bind(const T& t) { /* return value(). bind(t); */ if (Q_LIKELY(m) && m-> _bind(t)) return std::move(*static_cast<TResult*>(this)) ; return TResult (); }
template<typename T> TResult bind( T& t) { /* return value(). bind(t); */ if (Q_LIKELY(m) && m-> _bind(t)) return std::move(*static_cast<TResult*>(this)) ; return TResult (); }
template<typename T> TResult bind( T&& t) { /* return value(). bind(t); */ if (Q_LIKELY(m) && m-> _bind(t)) return std::move(*static_cast<TResult*>(this)) ; return TResult (); }
protected:
QScopedResult(TImpl* result, bool owned) : m(result), m_owned(owned) {}
......@@ -181,11 +181,11 @@ public:
Val<TResult> value() { return Val<TResult>(std::move(*static_cast<TResult*>(this))); }
// Shortcuts
/**/ Seq<TResult> sequence() { return value().sequence(); }
/**/ TResult null() { return value(). null(); }
template<typename T> TResult bind(const T& t) { return value(). bind(t); } // TODO only for readers ?
template<typename T> TResult bind( T& t) { return value(). bind(t); }
template<typename T> TResult bind( T&& t) { return value(). bind(t); }
/**/ Seq<TResult> sequence() { /* return value().sequence(); */ TResult* r=static_cast<TResult*>(this); if (Q_LIKELY(*r) && r->_sequence()) return Seq<TResult>(std::move(*r)); return Seq<TResult>(); }
/**/ TResult null() { /* return value(). null(); */ TResult* r=static_cast<TResult*>(this); if (Q_LIKELY(*r) && r-> _null()) return std::move(*r) ; return TResult (); }
template<typename T> TResult bind(const T& t) { /* return value(). bind(t); */ TResult* r=static_cast<TResult*>(this); if (Q_LIKELY(*r) && r-> _bind(t)) return std::move(*r) ; return TResult (); }
template<typename T> TResult bind( T& t) { /* return value(). bind(t); */ TResult* r=static_cast<TResult*>(this); if (Q_LIKELY(*r) && r-> _bind(t)) return std::move(*r) ; return TResult (); }
template<typename T> TResult bind( T&& t) { /* return value(). bind(t); */ TResult* r=static_cast<TResult*>(this); if (Q_LIKELY(*r) && r-> _bind(t)) return std::move(*r) ; return TResult (); }
};
// //////////////////////////////////////////////////////////////////////////
......@@ -338,7 +338,6 @@ struct QBind<TSrcResult, Val<TDst>> { static TSrcResult bind(Val<TSrcResult> src
/**/ dst.null();
return src.null();
}};
// //////////////////////////////////////////////////////////////////////////
......
......@@ -118,6 +118,7 @@ public:
operator bool() { return io; } // for QMovedResult
protected:
friend class QMovedResult<CborWriter, BindMode::Write>;
template<class T_> friend class Val; // calls methods below
bool _sequence() { levels++;
......
......@@ -74,6 +74,7 @@ class QJsonBuilderImpl
public:
QJsonBuilderImpl(QJsonValue* v) : result(v) { Q_ASSERT(v); }
protected:
friend class QScopedResult<QJsonBuilder, QJsonBuilderImpl, BindMode::Write>; // for slight optimization of fluent interface shortcuts
template<class T_> friend class Val; // calls methods below
bool _record() { levels.push(Step("" )); return true; }
......@@ -133,6 +134,7 @@ public:
QJsonWriterImpl(QIODevice* io) : io(io) { Q_ASSERT(io); }
~QJsonWriterImpl() { for (auto&& level : levels) io->write(level.end); }
protected:
friend class QScopedResult<QJsonWriter, QJsonWriterImpl, BindMode::Write>;
template<class T_> friend class Val; // calls methods below
bool _sequence() { levels.push(Step{"","]"});
......@@ -190,6 +192,7 @@ public:
QVector<QTextReadError> errors;
protected:
friend class QScopedResult<QJsonReader, QJsonReaderImpl, BindMode::Write>;
template<class T_> friend class Val; // calls methods below
bool _sequence() { if (get('[', "[{\"ntf-0123456789.")) {
......
......@@ -83,6 +83,7 @@ public:
operator bool() { return io; } // for QMovedResult
protected:
friend class QMovedResult<TextWriter, BindMode::Write>;
template<class T_> friend class Val; // enables calling methods below through operator->()
bool _sequence() { io->write("["); return true; }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment