From dbcbf305b2525493b4dea2530af4f91fe7ca436c Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Sun, 4 Dec 2016 18:28:02 +0100 Subject: [PATCH] Improve prediction of block outside covered areas --- src/frontends/qt4/GuiSymbols.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/frontends/qt4/GuiSymbols.cpp b/src/frontends/qt4/GuiSymbols.cpp index 9f7dd6105b..e2c0f04ec4 100644 --- a/src/frontends/qt4/GuiSymbols.cpp +++ b/src/frontends/qt4/GuiSymbols.cpp @@ -152,6 +152,7 @@ const int no_blocks = sizeof(unicode_blocks) / sizeof(UnicodeBlocks); QString getBlock(char_type c) { // store an educated guess for the next search + // 0 <= lastBlock < no_blocks // FIXME THREAD static int lastBlock = 0; @@ -159,10 +160,6 @@ QString getBlock(char_type c) 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) @@ -177,8 +174,18 @@ QString getBlock(char_type c) int i = 0; while (i < no_blocks && c > unicode_blocks[i].end) ++i; - if (i == no_blocks || c < unicode_blocks[i].start) + + if (i == no_blocks) return QString(); + + if (c < unicode_blocks[i].start) { + // 0 < i < no_blocks + // cache the previous block for guessing next time + lastBlock = i - 1; + return QString(); + } + + // 0 <= i < no_blocks // cache the last block for guessing next time lastBlock = i; return unicode_blocks[lastBlock].qname; -- 2.39.5