diff options
author | Zufu Liu <unknown> | 2021-09-14 11:54:02 +1000 |
---|---|---|
committer | Zufu Liu <unknown> | 2021-09-14 11:54:02 +1000 |
commit | 8c847dde89ba002a8c54fd757ae16a43247c9bd0 (patch) | |
tree | 3b4c342462a921305549f193bb0beb92c99746da | |
parent | 4c33ed1eadb5aae24ca1752a82cf4045a32d8fe0 (diff) | |
download | scintilla-mirror-8c847dde89ba002a8c54fd757ae16a43247c9bd0.tar.gz |
Avoid some allocations when checking whether font monospaced.
-rw-r--r-- | scripts/HeaderOrder.txt | 1 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 13 |
2 files changed, 8 insertions, 6 deletions
diff --git a/scripts/HeaderOrder.txt b/scripts/HeaderOrder.txt index c2b198ed3..a0954fcce 100644 --- a/scripts/HeaderOrder.txt +++ b/scripts/HeaderOrder.txt @@ -41,6 +41,7 @@ #include <string> #include <string_view> #include <vector> +#include <array> #include <map> #include <set> #include <forward_list> diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index ad1340d0d..cc65b16cb 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -14,6 +14,7 @@ #include <string> #include <string_view> #include <vector> +#include <array> #include <map> #include <set> #include <optional> @@ -68,12 +69,12 @@ void FontRealised::Realise(Surface &surface, int zoomLevel, Technology technolog measurements.spaceWidth = surface.WidthText(font.get(), " "); if (fs.checkMonospaced) { - std::string allASCIIGraphic("Ayfi"); // "Ay" is normally strongly kerned and "fi" may be a ligature - for (unsigned char ch = 0x20; ch <= 0x7E; ch++) { - allASCIIGraphic.push_back(ch); - } - std::vector<XYPOSITION> positions(allASCIIGraphic.length()); - surface.MeasureWidths(font.get(), allASCIIGraphic, positions.data()); + // "Ay" is normally strongly kerned and "fi" may be a ligature + constexpr std::string_view allASCIIGraphic("Ayfi" + // python: ''.join(chr(ch) for ch in range(32, 127)) + " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"); + std::array<XYPOSITION, allASCIIGraphic.length()> positions; + surface.MeasureWidthsUTF8(font.get(), allASCIIGraphic, positions.data()); std::adjacent_difference(positions.begin(), positions.end(), positions.begin()); const XYPOSITION maxWidth = *std::max_element(positions.begin(), positions.end()); const XYPOSITION minWidth = *std::min_element(positions.begin(), positions.end()); |