summaryrefslogtreecommitdiff
path: root/src/gfx_layout.cpp
diff options
context:
space:
mode:
authorFrédéric Simonis <simonisfrederic@gmail.com>2021-08-16 11:18:47 +0200
committerGitHub <noreply@github.com>2021-08-16 11:18:47 +0200
commitac4a7d02c7e6fdd76af801f7eeabc1e9efeefcff (patch)
tree1c02ab08e770b5ad0a1c2a7f59f52600a149e466 /src/gfx_layout.cpp
parent2e6a77a78a465797a5e78c55c6b16f45fc104e5c (diff)
downloadopenttd-ac4a7d02c7e6fdd76af801f7eeabc1e9efeefcff.tar.xz
Codechange: Improve LineCache queries (#9417)
Adds the support to query the linecache without copying the string. This uses a custom transparent comparator in conjunction with a query type using a std::string_view.
Diffstat (limited to 'src/gfx_layout.cpp')
-rw-r--r--src/gfx_layout.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/gfx_layout.cpp b/src/gfx_layout.cpp
index 0baeb32d5..38f6d62e5 100644
--- a/src/gfx_layout.cpp
+++ b/src/gfx_layout.cpp
@@ -888,6 +888,12 @@ Layouter::LineCacheItem &Layouter::GetCachedParagraphLayout(const char *str, siz
linecache = new LineCache();
}
+ if (auto match = linecache->find(LineCacheQuery{state, std::string_view{str, len}});
+ match != linecache->end()) {
+ return match->second;
+ }
+
+ /* Create missing entry */
LineCacheKey key;
key.state_before = state;
key.str.assign(str, len);