8000 Fixing missing life rage protection for the reverse filter (and others). by jferreyra-sc · Pull Request #246 · jinja2cpp/Jinja2Cpp · GitHub
[go: up one dir, main page]

Skip to content

Fixing missing life rage protection for the reverse filter (and others). #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update filters.cpp
Fixing missing life rage protection for the reverse filter.
  • Loading branch information
jferreyra-sc authored Feb 9, 2024
commit a6f0366af22b387d69f50423df7c1e6b8bcff5e3
14 changes: 12 additions & 2 deletions src/filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,12 @@ InternalValue SequenceAccessor::Filter(const InternalValue& baseVal, RenderConte
auto size = listSize.value();
InternalValueList resultList(size);
for (std::size_t n = 0; n < size; ++n)
resultList[size - n - 1] = list.GetValueByIndex(n);
{
auto resultVal = InternalValue(std::move( list.GetValueByIndex(n) ));
if (baseVal.ShouldExtendLifetime())
resultVal.SetParentData(baseVal);
resultList[size - n - 1] = std::move(resultVal);
}
result = ListAdapter::CreateAdapter(std::move(resultList));
}
else
Expand All @@ -562,7 +567,12 @@ InternalValue SequenceAccessor::Filter(const InternalValue& baseVal, RenderConte
auto it = list.begin();
auto end = list.end();
for (; it != end; ++it)
resultList.push_back(*it);
{
auto resultVal = InternalValue(std::move( *it ));
if (baseVal.ShouldExtendLifetime())
resultVal.SetParentData(baseVal);
resultList.push_back(std::move(resultVal));
}

std::reverse(resultList.begin(), resultList.end());
result = ListAdapter::CreateAdapter(std::move(resultList));
Expand Down
0