From d00474f0fcdd7cc7361a9d5584d9c69a45c16e5e Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Mon, 16 Apr 2018 21:49:26 -0500 Subject: [PATCH] Optimize split_about --- src/wcstringutil.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/wcstringutil.h b/src/wcstringutil.h index 907ffb8d7..ad9404ede 100644 --- a/src/wcstringutil.h +++ b/src/wcstringutil.h @@ -41,16 +41,17 @@ void split_about(ITER haystack_start, ITER haystack_end, ITER needle_start, ITER if (split_point == haystack_end) { // not found break; } - wcstring result = wcstring(haystack_cursor, split_point); - if (!no_empty || result.size() > 0) { - output->push_back(std::move(result)); + if (!no_empty || haystack_cursor != split_point) { + output->emplace_back(haystack_cursor, split_point); } remaining--; // Need to skip over the needle for the next search note that the needle may be empty. haystack_cursor = split_point + std::distance(needle_start, needle_end); } // Trailing component, possibly empty. - output->push_back(wcstring(haystack_cursor, haystack_end)); + if (!no_empty || haystack_cursor != haystack_end) { + output->emplace_back(haystack_cursor, haystack_end); + } } enum class ellipsis_type {