@@ -209,7 +209,7 @@ template<class T, std::invocable<T> F>
209209requires convertible_to_php_bool<kphp::coro::async_function_return_type_t <F, T>>
210210kphp::coro::task<array<T>> array_filter_impl (array<T> a, F f) noexcept {
211211 array<T> result{a.size ()};
212- for (const auto & it : a ) {
212+ for (const auto & it : std::as_const (a) ) {
213213 bool condition{};
214214 if constexpr (kphp::coro::is_async_function_v<F, T>) {
215215 condition = f$boolval (co_await std::invoke (f, it.get_value ()));
@@ -227,7 +227,7 @@ template<class T, std::invocable<typename array<T>::const_iterator::key_type> F>
227227requires convertible_to_php_bool<kphp::coro::async_function_return_type_t <F, typename array<T>::const_iterator::key_type>>
228228kphp::coro::task<array<T>> array_filter_by_key_impl (array<T> a, F f) noexcept {
229229 array<T> result{a.size ()};
230- for (const auto & it : a ) {
230+ for (const auto & it : std::as_const (a) ) {
231231 bool condition{};
232232 if constexpr (kphp::coro::is_async_function_v<F, typename array<T>::const_iterator::key_type>) {
233233 condition = f$boolval (co_await std::invoke (f, it.get_key ()));
@@ -245,7 +245,7 @@ template<class T, class F>
245245requires convertible_to_php_bool<kphp::coro::async_function_return_type_t <F, typename array<T>::const_iterator::value_type>>
246246kphp::coro::task<std::tuple<typename array<T>::const_iterator::key_type, typename array<T>::const_iterator::value_type>> array_find_impl (array<T> a,
247247 F f) noexcept {
248- for (const auto & it : a ) {
248+ for (const auto & it : std::as_const (a) ) {
249249 bool condition{};
250250 if constexpr (kphp::coro::is_async_function_v<F, typename array<T>::const_iterator::value_type>) {
251251 condition = co_await std::invoke (f, it.get_value ());
@@ -339,7 +339,7 @@ mixed f$array_rand(const array<T>& a, int64_t num) noexcept {
339339template <class A , std::invocable<A> F, class R = kphp::coro::async_function_return_type_t <F, A>>
340340kphp::coro::task<array<R>> f$array_map(F f, array<A> a) noexcept {
341341 array<R> result{a.size ()};
342- for (const auto & it : a ) {
342+ for (const auto & it : std::as_const (a) ) {
343343 if constexpr (kphp::coro::is_async_function_v<F, A>) {
344344 result.set_value (it.get_key (), co_await std::invoke (f, it.get_value ()));
345345 } else {
@@ -353,7 +353,7 @@ template<class R, class T, std::invocable<R, T> F, class I>
353353requires std::constructible_from<R, std::add_rvalue_reference_t <I>>
354354kphp::coro::task<R> f$array_reduce(array<T> a, F f, I init) noexcept {
355355 R result{R (std::move (init))}; // explicit constructor call to avoid implicit cast
356- for (const auto & it : a ) {
356+ for (const auto & it : std::as_const (a) ) {
357357 if constexpr (kphp::coro::is_async_function_v<F, R, T>) {
358358 result = co_await std::invoke (f, result, it.get_value ());
359359 } else {
@@ -365,12 +365,9 @@ kphp::coro::task<R> f$array_reduce(array<T> a, F f, I init) noexcept {
365365
366366template <class T , class Comparator >
367367requires (std::invocable<Comparator, T, T>)
368- kphp::coro::task<> f$usort(array<T>& a, Comparator compare) {
368+ kphp::coro::task<> f$usort(array<T>& a, Comparator compare) noexcept {
369369 if constexpr (kphp::coro::is_async_function_v<Comparator, T, T>) {
370- /* ATTENTION: temporary copy is necessary since functions is coroutine and sort is inplace */
371- array<T> tmp{a};
372- co_await array_functions_impl_::async_sort<kphp::coro::task<>>(tmp, std::move (compare), true );
373- a = tmp;
370+ co_await array_functions_impl_::async_sort<kphp::coro::task<>>(a, std::move (compare), true );
374371 co_return ;
375372 } else {
376373 co_return a.sort (std::move (compare), true );
@@ -379,25 +376,19 @@ kphp::coro::task<> f$usort(array<T>& a, Comparator compare) {
379376
380377template <class T , class Comparator >
381378requires (std::invocable<Comparator, T, T>)
382- kphp::coro::task<> f$uasort(array<T>& a, Comparator compare) {
379+ kphp::coro::task<> f$uasort(array<T>& a, Comparator compare) noexcept {
383380 if constexpr (kphp::coro::is_async_function_v<Comparator, T, T>) {
384- /* ATTENTION: temporary copy is necessary since functions is coroutine and sort is inplace */
385- array<T> tmp{a};
386- co_await array_functions_impl_::async_sort<kphp::coro::task<>>(tmp, std::move (compare), false );
387- a = tmp;
381+ co_await array_functions_impl_::async_sort<kphp::coro::task<>>(a, std::move (compare), false );
388382 } else {
389383 co_return a.sort (std::move (compare), false );
390384 }
391385}
392386
393387template <class T , class Comparator >
394388requires (std::invocable<Comparator, typename array<T>::key_type, typename array<T>::key_type>)
395- kphp::coro::task<> f$uksort(array<T>& a, Comparator compare) {
389+ kphp::coro::task<> f$uksort(array<T>& a, Comparator compare) noexcept {
396390 if constexpr (kphp::coro::is_async_function_v<Comparator, typename array<T>::key_type, typename array<T>::key_type>) {
397- /* ATTENTION: temporary copy is necessary since functions is coroutine and sort is inplace */
398- array<T> tmp{a};
399- co_await array_functions_impl_::async_ksort<kphp::coro::task<>>(tmp, std::move (compare));
400- a = tmp;
391+ co_await array_functions_impl_::async_ksort<kphp::coro::task<>>(a, std::move (compare));
401392 } else {
402393 co_return a.ksort (std::move (compare));
403394 }
0 commit comments