diff options
author | mitchell <unknown> | 2019-04-16 22:50:17 -0400 |
---|---|---|
committer | mitchell <unknown> | 2019-04-16 22:50:17 -0400 |
commit | 86266d4700632860705fc2d4e88d4be4f5228be1 (patch) | |
tree | f330e0f843dcef19d0c69506fa1df4637ccd820e /lexlib/CharacterCategory.cxx | |
parent | 4c22cdbe64a4024053c202521b69524c655a2c5d (diff) | |
download | scintilla-mirror-86266d4700632860705fc2d4e88d4be4f5228be1.tar.gz |
Backport: Feature [feature-requests:#1259]. Add SCI_SETCHARACTERCATEGORYOPTIMIZATION API to optimize speed of character category features.
Backport of changeset 7392:2832adedd0f4, but with added includes for Sci::clamp().
Diffstat (limited to 'lexlib/CharacterCategory.cxx')
-rw-r--r-- | lexlib/CharacterCategory.cxx | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lexlib/CharacterCategory.cxx b/lexlib/CharacterCategory.cxx index bc2fa2336..19c44cabe 100644 --- a/lexlib/CharacterCategory.cxx +++ b/lexlib/CharacterCategory.cxx @@ -7,10 +7,13 @@ // Copyright 2013 by Neil Hodgson <neilh@scintilla.org> // The License.txt file describes the conditions under which this software may be distributed. +#include <vector> #include <algorithm> #include <iterator> +#include "Scintilla.h" // for ptrdiff_t in Position.h #include "CharacterCategory.h" +#include "Position.h" // for Sci::clamp namespace Scintilla { @@ -3790,6 +3793,7 @@ const int catRanges[] = { 33554397, 33554460, 35651549, +35651613, //--Autogenerated -- end of section automatically generated }; @@ -3963,4 +3967,33 @@ bool IsXidContinue(int character) { } } +CharacterCategoryMap::CharacterCategoryMap() noexcept { + Optimize(256); +} + +int CharacterCategoryMap::Size() const noexcept { + return static_cast<int>(dense.size()); +} + +void CharacterCategoryMap::Optimize(int countCharacters) { + const int characters = Sci::clamp(countCharacters, 256, maxUnicode + 1); + dense.resize(characters); + + int end = 0; + int index = 0; + int current = catRanges[index]; + ++index; + do { + const int next = catRanges[index]; + const unsigned char category = current & maskCategory; + current >>= 5; + end = std::min(characters, next >> 5); + while (current < end) { + dense[current++] = category; + } + current = next; + ++index; + } while (characters > end); +} + } |