[Qt-interest] QTextStrem.pos() incredible slow

Malyushytsky, Alex alex at wai.com
Thu Oct 28 23:50:02 CEST 2010


To me it does not look like a bug since QT documentation states that it is slow:

"
qint64 QTextStream::pos () const
Returns the device position corresponding to the current position of the stream, or -1 if an error occurs (e.g., if there is no device or string, or if there's a device error).

Because QTextStream is buffered, this function may have to seek the device to reconstruct a valid device position. This operation can be expensive, so you may want to avoid calling this function in a tight loop.
"

Regards,
    Alex


-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Niklaus Hersche
Sent: Thursday, October 28, 2010 5:55 AM
To: Qt-interest at trolltech.com
Subject: [Qt-interest] QTextStrem.pos() incredible slow

Hi

I scan a tag in a utf16 text file with QTextStrem.readLine().
Once I have found the tag, I'd like to keep the file position in memory for
further use.

Unfortunately QTextStrem.pos() is so slow, that it's almost of useless.

To find the tag it takes 281 ms.
The subsequent call of QTextStrem.pos() takes 14078 ms.

This is incredible, isn't it?

To me this looks like a bug. Has this issue been fixed in a later version,
or am I doing something  wrong?

Has anybody a clue?

Thanks
Nik



- QTextStrem.pos() returns: 6037728
- OS: WinXP
- Qt: 4.5.2

Simple code to reproduce the issue:
//-----------------------------------------------------------------------
bool test(){

        qint64 filePos = -1;
        QFile f(c_ProjectFile);
        QTextStream ts(&f);

        if(!f.open( QFile::ReadOnly | QFile::Text)){
                return false;
        }

        ts.setCodec("UTF-16LE");

        QTime tm1;
        tm1.start();

        for(QString line; !(line = ts.readLine()).isNull(); ){

                if(line.startsWith( c_StartTag, Qt::CaseInsensitive)){
                        int elapsed = tm1.elapsed();
                        qDebug() << "search: " << elapsed << " ms";

                        tm1.restart();
                        filePos = ts.pos();
                        elapsed = tm1.elapsed();
                        qDebug() << "pos: " << elapsed << " ms";
                        return true;
                }

        } // for

        return false;
}
//-----------------------------------------------------------------------






_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”

“Please consider our environment before printing this email.”




More information about the Qt-interest-old mailing list