From 1a9dcec56cccea81e8ff1a603f170fda2a7920a9 Mon Sep 17 00:00:00 2001 From: Yannic Staudt Date: Thu, 29 Feb 2024 16:25:35 +0100 Subject: [PATCH] :wrench: optimizing result value by std::move()-ing the result vectors from the paginating calls instead of copying into temporary --- gh/branches.hxx | 9 ++++++--- gh/issues.hxx | 2 +- gh/releases.hxx | 3 +-- gh/search.hxx | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/gh/branches.hxx b/gh/branches.hxx index 0b57ac4b..679c1349 100644 --- a/gh/branches.hxx +++ b/gh/branches.hxx @@ -44,6 +44,8 @@ BOOST_FUSION_ADAPT_STRUCT(gh::repos::branch_t, name, commit, protection_url, is_ namespace gh { + using namespace std::string_literals; + /** * \brief list github branches, passing them to the result_handler as std::vector. * See https://developer.github.com/v3/repos/branches/#list-branches @@ -54,7 +56,8 @@ namespace gh { * \param result_handler Callable with signature : `func(std::vector)` */ inline void list_branches(std::string owner, std::string repos, std::function&& result_handler, - std::optional auth = std::nullopt) { + std::optional auth = std::nullopt, + const std::string& api_endpoint = "https://api.github.com"s) { using namespace xxhr; std::function response_handler; @@ -94,14 +97,14 @@ namespace gh { do_request(next_page.value()); } else { - result_handler({all_branches.begin(), all_branches.end()}); + result_handler(std::move(all_branches)); } } else { throw std::runtime_error(resp.url + " failed with error: " + std::string(resp.error) + " - " + resp.text); } }; - auto url = "https://api.github.com/repos/"s + owner + "/" + repos + "/branches?" + gh::detail::pagination::get_per_page_query_string(); + auto url = api_endpoint + "/repos/" + owner + "/" + repos + "/branches?" + gh::detail::pagination::get_per_page_query_string(); do_request(url); } } diff --git a/gh/issues.hxx b/gh/issues.hxx index 1d917ecf..f0fb89b5 100644 --- a/gh/issues.hxx +++ b/gh/issues.hxx @@ -148,7 +148,7 @@ namespace gh { do_request(next_page.value()); } else { - result_handler({ all_issues.begin(), all_issues.end()}); + result_handler(std::move(all_issues)); } } else { throw std::runtime_error( "err : "s + std::string(resp.error) + "status: "s diff --git a/gh/releases.hxx b/gh/releases.hxx index 1f847de8..8e64c139 100644 --- a/gh/releases.hxx +++ b/gh/releases.hxx @@ -454,9 +454,8 @@ namespace gh { do_request(next_page.value()); } else { - result_handler({all_releases.begin(), all_releases.end()}); + result_handler(std::move(all_releases)); } - } else { throw std::runtime_error( "err : "s + std::string(resp.error) + "status: "s diff --git a/gh/search.hxx b/gh/search.hxx index eb6ab3a5..e7a6ade9 100644 --- a/gh/search.hxx +++ b/gh/search.hxx @@ -142,7 +142,7 @@ namespace gh { do_request(next_page.value(), xxhr::Parameters{}); } else { - result_handler({all_results.begin(), all_results.end()}); + result_handler(std::move(all_results)); } } else { throw std::runtime_error(resp.url + " failed with error: " + std::string(resp.error));