Skip to content

Commit

Permalink
[k2] do not pass callback by reference in preg_replace_callback (#1214)
Browse files Browse the repository at this point in the history
  • Loading branch information
apolyakov authored Jan 17, 2025
1 parent 042a713 commit 558e679
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions runtime-light/stdlib/string/regex-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ task_t<Optional<string>> f$preg_replace_callback(string pattern, F callback, str
}

template<class F>
task_t<Optional<string>> f$preg_replace_callback(mixed pattern, F &&callback, string subject, int64_t limit = kphp::regex::PREG_REPLACE_NOLIMIT,
task_t<Optional<string>> f$preg_replace_callback(mixed pattern, F callback, string subject, int64_t limit = kphp::regex::PREG_REPLACE_NOLIMIT,
int64_t &count = RegexInstanceState::get().default_preg_replace_count,
int64_t flags = kphp::regex::PREG_NO_FLAGS) noexcept {
if (!regex_impl_::valid_preg_replace_mixed(pattern)) [[unlikely]] {
co_return Optional<string>{};
}

if (pattern.is_string()) {
co_return co_await f$preg_replace_callback(std::move(pattern.as_string()), std::forward<F>(callback), std::move(subject), limit, count, flags);
co_return co_await f$preg_replace_callback(std::move(pattern.as_string()), std::move(callback), std::move(subject), limit, count, flags);
}

string result{subject};
Expand All @@ -146,15 +146,15 @@ task_t<Optional<string>> f$preg_replace_callback(mixed pattern, F &&callback, st
}

template<class F>
task_t<mixed> f$preg_replace_callback(mixed pattern, F &&callback, mixed subject, int64_t limit = kphp::regex::PREG_REPLACE_NOLIMIT,
task_t<mixed> f$preg_replace_callback(mixed pattern, F callback, mixed subject, int64_t limit = kphp::regex::PREG_REPLACE_NOLIMIT,
int64_t &count = RegexInstanceState::get().default_preg_replace_count,
int64_t flags = kphp::regex::PREG_NO_FLAGS) noexcept {
if (!regex_impl_::valid_preg_replace_mixed(pattern) || !regex_impl_::valid_preg_replace_mixed(subject)) [[unlikely]] {
co_return mixed{};
}

if (subject.is_string()) {
co_return co_await f$preg_replace_callback(std::move(pattern), std::forward<F>(callback), std::move(subject.as_string()), limit, count, flags);
co_return co_await f$preg_replace_callback(std::move(pattern), std::move(callback), std::move(subject.as_string()), limit, count, flags);
}

const auto &subject_arr{subject.as_array()};
Expand Down

0 comments on commit 558e679

Please sign in to comment.