From 51f84229296733c55361299206aa7651a0596b8b Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 7 Jun 2021 01:20:29 +0200 Subject: [PATCH] Make HTML entity map static. Drastically reduces allocations. --- src/helpers.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers.cpp b/src/helpers.cpp index 6638327..91cc220 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -43,7 +43,7 @@ std::string unescape_html(const std::string_view html) // Source: https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_ // entity_references#Character_entity_references_in_HTML - const std::map + static const std::map names{{"exclamation", 0x0021}, {"quot", 0x0022}, {"percent", 0x0025}, {"amp", 0x0026}, {"apos", 0x0027}, {"add", 0x002B}, {"lt", 0x003C}, {"equal", 0x003D}, {"gt", 0x003E}, @@ -150,7 +150,7 @@ std::string unescape_html(const std::string_view html) try { const char32_t codepoint{ - [&match, &names] + [&match] { // If it doesn't start with a '#' it is a named entity. if (match[1].str()[0] != '#')