From: Abdelrazak Younes Date: Sat, 18 Oct 2008 14:14:58 +0000 (+0000) Subject: Fix part of http://bugzilla.lyx.org/show_bug.cgi?id=5347 X-Git-Tag: 1.6.10~2998 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=8a916f28a9e9ac4002ebceebd4eabb82783d1bd7;p=features.git Fix part of http://bugzilla.lyx.org/show_bug.cgi?id=5347 Use crc checking in order to decide if the widget needs to be updated or not. This speed up a lot the cursor moving use case. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26946 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp index b83082336f..ae5d9ff4b9 100644 --- a/src/frontends/qt4/GuiViewSource.cpp +++ b/src/frontends/qt4/GuiViewSource.cpp @@ -28,6 +28,8 @@ #include "support/docstream.h" #include "support/gettext.h" +#include + #include #include #include @@ -69,10 +71,19 @@ ViewSourceWidget::ViewSourceWidget() } +static size_t crcCheck(docstring const & s) +{ + boost::crc_32_type crc; + crc.process_bytes(&s[0], sizeof(char_type) * s.size()); + return crc.checksum(); +} + + /** get the source code of selected paragraphs, or the whole document \param fullSource get full source code + \return true if the content has changed since last call. */ -static QString getContent(BufferView const * view, bool fullSource) +static bool getContent(BufferView const * view, bool fullSource, QString & qstr) { // get the *top* level paragraphs that contain the cursor, // or the selected text @@ -90,7 +101,14 @@ static QString getContent(BufferView const * view, bool fullSource) swap(par_begin, par_end); odocstringstream ostr; view->buffer().getSourceCode(ostr, par_begin, par_end + 1, fullSource); - return toqstr(ostr.str()); + docstring s = ostr.str(); + static size_t crc = 0; + size_t newcrc = crcCheck(s); + if (newcrc == crc) + return false; + crc = newcrc; + qstr = toqstr(s); + return true; } @@ -108,7 +126,9 @@ void ViewSourceWidget::updateView() return; } - document_->setPlainText(getContent(bv_, viewFullSourceCB->isChecked())); + QString content; + if (getContent(bv_, viewFullSourceCB->isChecked(), content)) + document_->setPlainText(content); CursorSlice beg = bv_->cursor().selectionBegin().bottom(); CursorSlice end = bv_->cursor().selectionEnd().bottom();