Skip to content

Commit

Permalink
Merge branch 'var_copy' into 'master'
Browse files Browse the repository at this point in the history
Do not copy vector

See merge request OpenMW/openmw!3401
  • Loading branch information
psi29a committed Sep 5, 2023
2 parents 1a4b29f + a849a05 commit 58a3fcb
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions components/lua/utf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,19 @@ namespace LuaUtf8
};

utf8["codes"] = [](std::string_view s) {
std::vector<int64_t> pos_byte{ 1 };
return sol::as_function([s, pos_byte]() mutable -> sol::optional<std::pair<int64_t, int64_t>> {
if (pos_byte.back() <= static_cast<int64_t>(s.size()))
{
const auto pair = decodeNextUTF8Character(s, pos_byte);
if (pair.second == -1)
throw std::runtime_error("Invalid UTF-8 code at position " + std::to_string(pos_byte.size()));

return pair;
}
return sol::nullopt;
});
return sol::as_function(
[s, pos_byte = std::vector<int64_t>{ 1 }]() mutable -> sol::optional<std::pair<int64_t, int64_t>> {
if (pos_byte.back() <= static_cast<int64_t>(s.size()))
{
const auto pair = decodeNextUTF8Character(s, pos_byte);
if (pair.second == -1)
throw std::runtime_error(
"Invalid UTF-8 code at position " + std::to_string(pos_byte.size()));

return pair;
}
return sol::nullopt;
});
};

utf8["len"] = [](std::string_view s,
Expand Down

0 comments on commit 58a3fcb

Please sign in to comment.