Commit eb41001e authored by Stefan Brüns's avatar Stefan Brüns Committed by Albert Astals Cid
Browse files

[EPubGenerator] Avoid pointless scans of the whole document

The "<video></video>" tag is a placeholder, and should only be processed
when it has been inserted for this toc item, i.e. when movieAnnots is
non-empty. Also place the search cursor at the last inserted block,
otherwise the expression will search from the beginning of the document.

Do likewise for audio/soundActions.

This makes loading large documents much fasters, and even fixes crashing
on huge documents, e.g. from project Gutenberg "The Complete Works of
William Shakespeare" (3200 pages) or the "King James Bible" (1400 pages).

Test Plan: open a large EPub file (see above)

Reviewers: #okular, aacid

Reviewed By: #okular, aacid

Subscribers: aacid, okular-devel

Tags: #okular

Differential Revision:
parent 9f98c010
......@@ -307,10 +307,10 @@ QTextDocument* Converter::convert( const QString &fileName )
QTextCursor csr(mTextDocument); // a temporary cursor
QTextCursor csr(before); // a temporary cursor pointing at the begin of the last inserted block
int index = 0;
while( !(csr = mTextDocument->find(QStringLiteral("<video></video>"),csr)).isNull() ) {
while( !movieAnnots.isEmpty() && !(csr = mTextDocument->find(QStringLiteral("<video></video>"),csr)).isNull() ) {
const int posStart = csr.position();
const QPoint startPoint = calculateXYPosition(mTextDocument, posStart);
QImage img(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("okular/pics/okular-epub-movie.png")));
......@@ -323,10 +323,10 @@ QTextDocument* Converter::convert( const QString &fileName )
csr = QTextCursor(before);
index = 0;
const QString keyToSearch(QStringLiteral("<audio></audio>"));
while( !(csr = mTextDocument->find(keyToSearch, csr)).isNull() ) {
while( !soundActions.isEmpty() && !(csr = mTextDocument->find(keyToSearch, csr)).isNull() ) {
const int posStart = csr.position() - keyToSearch.size();
const QImage img(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("okular/pics/okular-epub-sound-icon.png")));
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