mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Avoid extra allocations
This commit is contained in:
parent
dadbd4cd47
commit
2a41dca9d4
3 changed files with 3443 additions and 3442 deletions
|
@ -1488,18 +1488,19 @@ struct Compiler
|
|||
|
||||
for (AstArray<char> const& string : expr->strings)
|
||||
{
|
||||
std::string stringEscaped(string.data);
|
||||
if (memchr(string.data, '%', string.size))
|
||||
{
|
||||
for (size_t characterIndex = 0; characterIndex < string.size; ++characterIndex)
|
||||
{
|
||||
char character = string.data[characterIndex];
|
||||
formatString.push_back(character);
|
||||
|
||||
for (size_t characterIndex = 0; characterIndex < stringEscaped.size(); ++characterIndex)
|
||||
{
|
||||
if (stringEscaped[characterIndex] == '%')
|
||||
{
|
||||
stringEscaped.insert(characterIndex, 1, '%');
|
||||
characterIndex++;
|
||||
if (character == '%')
|
||||
formatString.push_back('%');
|
||||
}
|
||||
}
|
||||
|
||||
formatString += stringEscaped;
|
||||
else
|
||||
formatString += std::string(string.data, string.size);
|
||||
|
||||
stringsLeft--;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue