1
0
mirror of synced 2025-01-19 01:24:15 +01:00

perf(pattern): save display value in cache (#466)

Co-authored-by: Dmitry Polshakov <dmitry.polshakov@dsr-corporation.com>
This commit is contained in:
Polshakov Dmitry 2022-03-16 02:01:01 +03:00 committed by GitHub
parent 3801e0d60b
commit d677762dff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -211,7 +211,7 @@ namespace hex::pl {
this->m_local == other.m_local;
}
[[nodiscard]] std::string formatDisplayValue(const std::string &value, const Token::Literal &literal) const {
[[nodiscard]] std::string calcDisplayValue(const std::string &value, const Token::Literal &literal) const {
if (!this->m_formatterFunction.has_value())
return value;
else {
@ -232,6 +232,14 @@ namespace hex::pl {
}
}
[[nodiscard]] std::string formatDisplayValue(const std::string &value, const Token::Literal &literal) const {
if (!this->m_cachedDisplayValue.has_value()) {
this->m_cachedDisplayValue = calcDisplayValue(value, literal);
}
return this->m_cachedDisplayValue.value();
}
protected:
void createDefaultEntry(const std::string &value, Token::Literal &&literal) const {
ImGui::TableNextRow();
@ -279,6 +287,7 @@ namespace hex::pl {
u32 m_color = 0x00;
std::optional<std::string> m_displayName;
mutable std::optional<std::string> m_cachedDisplayValue;
std::string m_variableName;
std::optional<std::string> m_comment;
std::string m_typeName;