Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
4.5.0, 4.8.3, 5.0.0
Description
Run the attached example with Qt 4.3.3 and click on the "Replace Test"
button. The program does 10000 text replaces in 20000 lines of text.
Under Qt 4.3.3 this takes about 11 seconds on a PC with 2.6GHz. I would
expect this to work a lot faster!
Doing the same with Qt 4.5 (snapshot 20090116) takes 205 seconds on
the same machine - this is absolutely unusable!
Commenting out the insertText line will bring run time from 200+ to 2 seconds.
Example:
#include <qapplication.h> #include <qdialog.h> #include <qlineedit.h> #include <qstring.h> #include <qtextcursor.h> #include <qtextdocument.h> #include <qtextedit.h> #include <qpushbutton.h> #include <qlayout.h> #include <stdio.h> #include <time.h> #include <QDebug> class cTextEditor : public QDialog { Q_OBJECT private: QTextEdit *edit; QPushButton *b; private slots: void ReplaceTest(void); public: cTextEditor(void); }; cTextEditor::cTextEditor(void) { QVBoxLayout *vbl = new QVBoxLayout(this); edit = new QTextEdit; vbl->addWidget(edit); b = new QPushButton("Replace Test"); vbl->addWidget(b); connect(b, SIGNAL(clicked(bool)), SLOT(ReplaceTest())); resize(400, 200); QString qs; for (int i = 10000; --i > 0; ) qs += "Layer 1;\nRect R0 (5.25 -4.75) (5.75 -4.25);\n"; edit->setPlainText(qs); } void cTextEditor::ReplaceTest(void) { QTextDocument *d = edit->document(); if (d) { time_t t0 = time(NULL); QString FindText = "Layer 1;", Replace = "Layer 94;"; setUpdatesEnabled(false); QTextCursor tc; b->setDisabled(true); for (;;) { tc = d->find(FindText, tc, QTextDocument::FindCaseSensitively); if (tc.isNull()) break; tc.insertText(Replace); edit->setTextCursor(tc); } b->setDisabled(false); setUpdatesEnabled(true); fprintf(stderr, "time = %ds\n", time(NULL) - t0); } } int main(int argc, char **argv) { QApplication a(argc, argv); QDialog *d = new cTextEditor; d->show(); return a.exec(); } #include "main.moc"
Attachments
Issue Links
- relates to
-
QTBUG-50362 Document that beginEditBlock()/endEditBlock() should be used for large amounts of cursor operations
-
- Open
-
- replaces
-
QTBUG-10253 QTextEdit performance, slow inserting
-
- Closed
-