Make HTML entity map static.
continuous-integration/drone/push Build is passing Details

Drastically reduces allocations.
This commit is contained in:
tastytea 2021-06-07 01:20:29 +02:00
parent 8b5c0d289e
commit 51f8422929
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 2 additions and 2 deletions

View File

@ -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<std::string_view, char32_t>
static const std::map<std::string_view, char32_t>
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] != '#')