Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 7c5fe8f7 authored by EXT Arnaud Clère's avatar EXT Arnaud Clère
Browse files

Interesting perf improvement for all writers using item(const char*)

instead of item(QByteArray)
parent 185fedcf
......@@ -379,7 +379,7 @@ struct IWriter
virtual bool _record (quint32* size=nullptr) = 0;
virtual bool _null ( ) = 0;
virtual bool _item ( QUtf8String& name) = 0; // TODO Implement _item(QName n) instead
virtual bool _item ( QName name) = 0;
virtual bool _item ( ) = 0;
virtual bool _bind ( const char* utf8) = 0;
......@@ -447,12 +447,12 @@ protected:
template<class T_> friend class Seq; // enables calling methods below
template<class T_> friend class Rec;
bool _item(QUtf8String& n) { Q_ASSERT(impl); return impl->_item(n); }
bool _item(QUtf8String& n) { Q_ASSERT(impl); return impl->_item(n.constData()); }
bool _item( ) { Q_ASSERT(impl); return impl->_item( ); }
bool _out ( ) { Q_ASSERT(impl); return impl->_out ( ); }
// Literals support
bool _item( QName name) { Q_ASSERT(impl); QUtf8String n(QUtf8String::fromRawData(name,int(strlen(name)))); return impl->_item(n); }
bool _item( QName n) { Q_ASSERT(impl); return impl->_item(n); }
private:
IWriter* impl = nullptr; // this state has noticeable performance cost but guarantees well-formedness through a unique valid instance of QWriter (with impl != nullptr)
};
......
......@@ -142,9 +142,9 @@ protected:
bool _bind ( qlonglong& t) { return t<0 ? putInteger(quint64(-1-t), cbor::NegativeIntType) // see https://tools.ietf.org/html/rfc7049#section-2.1
: putInteger(quint64( t), cbor::UnsignedIntType); }
bool _item(QUtf8String& k) { return (Q_LIKELY(putInteger(quint64(k.size()), cbor::TextStringType)) && (Q_LIKELY(io->write(k)) || k.isEmpty())); }
bool _item( ) { return true ; }
bool _out ( ) { bool definite = levels.back(); levels.pop_back(); return definite ? true : putSimpleValue(cbor::Break); }
bool _item(QName n) { return (Q_LIKELY(putInteger(qstrlen(n), cbor::TextStringType)) && (Q_LIKELY(io->write(n)) || *n=='\0')); }
bool _item( ) { return true ; }
bool _out ( ) { bool definite = levels.back(); levels.pop_back(); return definite ? true : putSimpleValue(cbor::Break); }
private:
inline bool putMajorValue (cbor:: MajorValue v, cbor::MajorType majorType) { return io->putChar (v|char ( majorType << 5)); }
inline bool putSimpleValue(cbor::SimpleValue v ) { return io->putChar (v|char (cbor::SimpleValueType << 5)); }
......@@ -357,18 +357,18 @@ public:
/**/ Seq<QWriter> sequence(quint32* s=nullptr) { return QWriter(this).sequence ( s); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).bind(std::forward<T>(t)); }
protected:
virtual bool _sequence(quint32* rows=nullptr) { Q_UNUSED(rows); levels.push(Step(nullptr)); return true; }
virtual bool _record (quint32* cols=nullptr) { Q_UNUSED(cols); levels.push(Step("" )); return true; }
virtual bool _null ( ) { set(QCborValue( )); return true; }
virtual bool _bind ( const char* s) { set(QCborValue(s)); return true; }
virtual bool _bind ( bool& b) { set(QCborValue(b)); return true; }
virtual bool _bind ( double& d) { set(QCborValue(d)); return true; }
virtual bool _bind ( qulonglong& n) { double d(n); return _bind(d); }
virtual bool _bind ( qlonglong& n) { double d(n); return _bind(d); }
virtual bool _item(QUtf8String& k) { levels.last().key=k ; return true; }
virtual bool _item( ) { levels.last().key=nullptr; return true; }
virtual bool _out ( ) { auto level = levels.pop(); set(!level.key.isNull() ? QCborValue(level.object) : QCborValue(level.array)); return true; }
bool _sequence(quint32* s=nullptr) { Q_UNUSED(s); levels.push(Step(nullptr)); return true; }
bool _record (quint32* s=nullptr) { Q_UNUSED(s); levels.push(Step("" )); return true; }
bool _null ( ) { set(QCborValue( )); return true; }
bool _bind ( const char* s) { set(QCborValue(s)); return true; }
bool _bind ( bool& b) { set(QCborValue(b)); return true; }
bool _bind ( double& d) { set(QCborValue(d)); return true; }
bool _bind ( qulonglong& n) { double d(n); return _bind(d); }
bool _bind ( qlonglong& n) { double d(n); return _bind(d); }
bool _item(QName n) { levels.last().key=n ; return true; }
bool _item( ) { levels.last().key=nullptr; return true; }
bool _out ( ) { auto level = levels.pop(); set(!level.key.isNull() ? QCborValue(level.object) : QCborValue(level.array)); return true; }
private:
void set(const QCborValue& v) {
if (levels.isEmpty()) {
......
......@@ -69,25 +69,24 @@ public:
protected:
friend class QBaseWriter<QDataWriter>;
template<class T_> friend class Val; // calls methods below
template<class T_> friend class Seq;
template<class T_> friend class Rec;
bool _isOk() { return io && io->status()==QDataStream::Ok; }
bool _sequence(quint32* rows=nullptr) { if (rows) *io << *rows; return true; }
bool _record (quint32* cols=nullptr) { if (cols) *io << *cols; return true; }
bool _null ( ) { *io << nullptr; return true; }
bool _sequence(quint32* s=nullptr) { if (s) *io << *s; return true; }
bool _record (quint32* s=nullptr) { if (s) *io << *s; return true; }
bool _null ( ) { *io << nullptr; return true; }
template<typename T>
bool _bind ( T& t) { *io << t; return true; } // Use QVariant to explicit the parts that may be unknown to the reader
bool _bind ( const char* s) { QByteArray ba = QByteArray::fromRawData(s, int(qstrlen(s))); return _bind(ba); }
bool _bind ( T& t) { *io << t; return true; } // Use QVariant to explicit the parts that may be unknown to the reader
bool _bind ( const char* s) { QByteArray ba = QByteArray::fromRawData(s, int(qstrlen(s))); return _bind(ba); } // TODO FIXME
template<class T_> friend class Seq; // calls methods below
template<class T_> friend class Rec; // calls methods below
bool _isOk() { return io && io->status()==QDataStream::Ok; }
bool _item(QUtf8String&) { return true; } // record keys are implicit, maps should be serialized as a sequence of records with key and value items
bool _item( ) { return true; }
bool _out( ) { return true; }
bool _item( ) { return true; }
bool _item(QUtf8String&) { return true; } // record keys are implicit, maps should be serialized as a sequence of records with key and value items
// Literals support
bool _item( QName) { return true; }
bool _item( QName) { return true; } // for QBaseWriter
private:
QDataStream* io;
};
......
......@@ -72,9 +72,9 @@ protected:
bool _bind ( qulonglong& n) { double d(n); return _bind(d); }
bool _bind ( qlonglong& n) { double d(n); return _bind(d); }
bool _item(QUtf8String& k) { levels.last().key=k ; return true; }
bool _item( ) { levels.last().key=nullptr; return true; }
bool _out ( ) { auto level = levels.pop(); set(!level.key.isNull() ? QJsonValue(level.object) : QJsonValue(level.array)); return true; }
bool _item(QName n) { levels.last().key=n ; return true; }
bool _item( ) { levels.last().key=nullptr; return true; }
bool _out ( ) { auto level = levels.pop(); set(!level.key.isNull() ? QJsonValue(level.object) : QJsonValue(level.array)); return true; }
private:
void set(const QJsonValue& v) {
if (levels.isEmpty()) {
......@@ -191,9 +191,9 @@ protected:
bool _bind ( qulonglong& t) { return io->write(QUtf8String::number(qulonglong(t))); }
bool _bind ( qlonglong& t) { return io->write(QUtf8String::number( qlonglong(t))); }
bool _item(QUtf8String& k) { auto r=(io->write(levels.last().sep) || *levels.last().sep=='\0') && putString(k) && io->write(":"); levels.last().sep = ","; return r; }
bool _item( ) { auto r=(io->write(levels.last().sep) || *levels.last().sep=='\0') ; levels.last().sep = ","; return r; }
bool _out ( ) { return io->write(levels.pop() .end); }
bool _item(QName n) { auto r=(io->write(levels.last().sep) || *levels.last().sep=='\0') && putString(n) && io->write(":"); levels.last().sep = ","; return r; }
bool _item( ) { auto r=(io->write(levels.last().sep) || *levels.last().sep=='\0') ; levels.last().sep = ","; return r; }
bool _out ( ) { return io->write(levels.pop() .end); }
private:
struct Step { const char* sep; const char* end; };
......
......@@ -96,8 +96,8 @@ protected:
bool _sequence (quint32* s=nullptr) { if (d==T) { ++d; return true; } return false; }
bool _record (quint32* s=nullptr) { if (d==S) { ++d; return true; } return false; }
bool _item ( ) { if (d==S) { m->insertRows (idx.row(),1); idx=idx.sibling(idx.row()+1,idx.column()); return true; } return false; }
bool _item ( QUtf8String& k) { if (d==R) { // TODO Handle childrenName and names.indexOf(k)<0
idx=idx.sibling(idx.row(),names.indexOf(k)); return true; } return false; }
bool _item ( QName n) { if (d==R) { // TODO Handle childrenName and names.indexOf(k)<0
idx=idx.sibling(idx.row(),names.indexOf(n)); return true; } return false; }
private:
QAbstractItemModel* m;
QModelIndex idx;
......
......@@ -67,9 +67,9 @@ protected:
bool _sequence(quint32* rows=nullptr) { Q_UNUSED(rows); levels.push(Step(nullptr)); return true; }
bool _record (quint32* cols=nullptr) { Q_UNUSED(cols); levels.push(Step("" )); return true; }
bool _item(QUtf8String& k) { levels.last().key=k ; return true; }
bool _item( ) { levels.last().key=nullptr; return true; }
bool _out ( ) { auto level = levels.pop(); set(!level.key.isNull() ? QVariant(level.object) : QVariant(level.array)); return true; }
bool _item(QName n) { levels.last().key=n ; return true; }
bool _item( ) { levels.last().key=nullptr; return true; }
bool _out ( ) { auto level = levels.pop(); set(!level.key.isNull() ? QVariant(level.object) : QVariant(level.array)); return true; }
private:
void set(const QVariant& v) {
if (levels.isEmpty()) {
......
......@@ -121,9 +121,9 @@ protected:
bool _null ( ) { return true ; }
bool _bind ( const char* s) { return io->write( s ); }
bool _item(QUtf8String& k) { return io->write(" ") && io->write(k) && io->write(":"); }
bool _item( ) { return io->write(" ") ; }
bool _out ( ) { return io->write("]") ; }
bool _item(QName n) { return io->write(" ") && io->write(n) && io->write(":"); }
bool _item( ) { return io->write(" ") ; }
bool _out ( ) { return io->write("]") ; }
private:
QIODevice* io;
};
......
Markdown is supported
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