fixup! perf: sonarcloud warnings about temp objects (#3686) (#3699)

This commit is contained in:
Charles Kerr 2022-08-23 15:46:08 -05:00 committed by GitHub
parent 258faf3623
commit ab09718342
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -433,7 +433,7 @@ bool constexpr quarks_are_sorted()
static_assert(quarks_are_sorted(), "Predefined quarks must be sorted by their string value");
static_assert(std::size(my_static) == TR_N_KEYS);
auto& my_runtime{ *new std::vector<std::string>{} };
auto& my_runtime{ *new std::vector<std::string_view>{} };
} // namespace
@ -468,7 +468,11 @@ tr_quark tr_quark_new(std::string_view str)
}
auto const ret = TR_N_KEYS + std::size(my_runtime);
my_runtime.emplace_back(str);
auto const len = std::size(str);
auto* perma = new char[len + 1];
std::copy_n(std::begin(str), len, perma);
perma[len] = '\0';
my_runtime.emplace_back(perma);
return ret;
}