1
0
Fork 0

Codechange: Replace FontMap's std::map with std::vector.

pull/13126/head
Peter Nelson 2024-11-27 08:59:18 +00:00
parent e7c63de55d
commit c468e687e5
No known key found for this signature in database
GPG Key ID: 8EF8F0A467DF75ED
3 changed files with 6 additions and 6 deletions

View File

@ -105,8 +105,8 @@ static inline void GetLayouter(Layouter::LineCacheItem &line, std::string_view s
continue;
}
if (fontMapping.count(buff - buff_begin) == 0) {
fontMapping[buff - buff_begin] = f;
if (fontMapping.empty() || fontMapping.back().first != buff - buff_begin) {
fontMapping.emplace_back(buff - buff_begin, f);
}
f = Layouter::GetFont(state.fontsize, state.cur_colour);
}
@ -114,8 +114,8 @@ static inline void GetLayouter(Layouter::LineCacheItem &line, std::string_view s
/* Better safe than sorry. */
*buff = '\0';
if (fontMapping.count(buff - buff_begin) == 0) {
fontMapping[buff - buff_begin] = f;
if (fontMapping.empty() || fontMapping.back().first != buff - buff_begin) {
fontMapping.emplace_back(buff - buff_begin, f);
}
line.layout = T::GetParagraphLayout(buff_begin, buff, fontMapping);
line.state_after = state;

View File

@ -81,7 +81,7 @@ public:
};
/** Mapping from index to font. The pointer is owned by FontColourMap. */
using FontMap = std::map<int, Font *>;
using FontMap = std::vector<std::pair<int, Font *>>;
/**
* Interface to glue fallback and normal layouter into one.

View File

@ -102,7 +102,7 @@ public:
/* Extract font information for this run. */
CFRange chars = CTRunGetStringRange(run);
auto map = fontMapping.upper_bound(chars.location);
auto map = std::ranges::upper_bound(fontMapping, chars.location, std::less{}, &std::pair<int, Font *>::first);
this->emplace_back(run, map->second, buff);
}