]> git.lyx.org Git - features.git/commitdiff
improved position caching
authorAndré Pönitz <poenitz@gmx.net>
Fri, 21 Mar 2008 20:47:29 +0000 (20:47 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 21 Mar 2008 20:47:29 +0000 (20:47 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23889 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiSymbols.cpp
src/frontends/qt4/GuiSymbols.h

index 43c462d589d30b1e8c7a517f5f6fb09c4968ef86..314d8536d784b2cfd8f989714de1b9f8a985b5f8 100644 (file)
@@ -22,6 +22,7 @@
 #include "Encoding.h"
 #include "FuncRequest.h"
 
+#include "support/debug.h"
 #include "support/gettext.h"
 
 #include <QChar>
@@ -139,8 +140,8 @@ UnicodeBlocks unicode_blocks[] = {
        { N_("CJK Compatibility Ideographs Supplement"), 0x2f800, 0x2fa1f },
        { N_("Tags"), 0xe0000, 0xe007f },
        { N_("Variation Selectors Supplement"), 0xe0100, 0xe01ef },
-       { N_("Supplementary Private Use Area-A"), 0xf0000, 0xe01ef },
-       { N_("Supplementary Private Use Area-B"), 0x100000, 0x10ffff }
+       { N_("Supplementary Private Use Area-A"), 0xf0000, 0xffffd },
+       { N_("Supplementary Private Use Area-B"), 0x100000, 0x10fffd }
 };
 
 const int no_blocks = sizeof(unicode_blocks) / sizeof(UnicodeBlocks);
@@ -151,17 +152,32 @@ QString getBlock(char_type c)
        // store an educated guess for the next search
        static int lastBlock = 0;
 
-       if (c < unicode_blocks[lastBlock].start
-        || c > unicode_blocks[lastBlock].end)
-       {
-               // guess was wrong. do a real search.
-               int i = 0;
-               while (c > unicode_blocks[i].end && i < no_blocks)
-                       ++i;
-               if (unicode_blocks[i].name.isEmpty())
-                       return QString();
-               lastBlock = i;
-       }
+       // "clever reset"
+       if (c < 0x7f)
+               lastBlock = 0;
+
+       // off the end already
+       if (lastBlock == no_blocks)
+               return QString();
+
+       // c falls into a covered area, and we can guess which
+       if (c >= unicode_blocks[lastBlock].start
+           && c <= unicode_blocks[lastBlock].end)
+               return unicode_blocks[lastBlock].name;
+
+       // c falls into an uncovered area, but we can guess which       
+       if (c > unicode_blocks[lastBlock].end
+           && c < unicode_blocks[lastBlock + 1].start)
+               return QString();
+
+       // guessing was wrong so far. do a real search.
+       int i = 0;
+       while (c > unicode_blocks[i].end && i < no_blocks)
+               ++i;
+       if (i == no_blocks)
+               return QString();
+       lastBlock = i;
+       //LYXERR0("fail: " << int(c) << ' ' << lastBlock);
        return unicode_blocks[lastBlock].name;
 }
 
@@ -388,7 +404,7 @@ void GuiSymbols::updateSymbolList(bool update_combo)
        bool const show_all = categoryFilterCB->isChecked();
 
        if (symbols_.empty() || update_combo)
-               symbols_ = encodings.getFromLyXName(encoding_)->getSymbolsList();
+               symbols_ = encodings.getFromLyXName(encoding_)->symbolsList();
 
        if (!show_all) {
                for (int i = 0 ; i < no_blocks; ++i)
index 3c250a1de67451f75afe39f401cd53d16baa156a..94126f94a22398f32c7953699fe02e56255c40d7 100644 (file)
@@ -16,7 +16,7 @@
 #include "ui_SymbolsUi.h"
 
 #include <map>
-#include <set>
+#include <vector>
 
 namespace lyx {
 namespace frontend {
@@ -62,7 +62,7 @@ private:
        ///
        UsedBlocks used_blocks;
        /// list of all symbols
-       typedef std::set<char_type> SymbolsList;
+       typedef std::vector<char_type> SymbolsList;
        ///
        SymbolsList symbols_;
        /// custom model for symbol list view