From dfbf7c6f30ce1b01cff23c364b7951b7e7f2e483 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 29 Jul 2023 14:16:09 +0100 Subject: getURLParam needn't go through the optional helpers --- icespider/core/ihttpRequest.cpp | 2 +- icespider/core/ihttpRequest.h | 4 ++-- icespider/unittests/testPerf.cpp | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/icespider/core/ihttpRequest.cpp b/icespider/core/ihttpRequest.cpp index 64a891d..461fc9e 100644 --- a/icespider/core/ihttpRequest.cpp +++ b/icespider/core/ihttpRequest.cpp @@ -132,7 +132,7 @@ namespace IceSpider { } } - OptionalString + std::string_view IHttpRequest::getURLParamStr(const unsigned int idx) const { auto & url = getRequestPath(); diff --git a/icespider/core/ihttpRequest.h b/icespider/core/ihttpRequest.h index 6876c2b..2b4ac02 100644 --- a/icespider/core/ihttpRequest.h +++ b/icespider/core/ihttpRequest.h @@ -46,7 +46,7 @@ namespace IceSpider { [[nodiscard]] virtual PathElements & getRequestPath() = 0; [[nodiscard]] virtual HttpMethod getRequestMethod() const = 0; - [[nodiscard]] OptionalString getURLParamStr(const unsigned int) const; + [[nodiscard]] std::string_view getURLParamStr(const unsigned int) const; [[nodiscard]] virtual OptionalString getQueryStringParamStr(const std::string_view) const = 0; [[nodiscard]] virtual OptionalString getHeaderParamStr(const std::string_view) const = 0; [[nodiscard]] virtual OptionalString getCookieParamStr(const std::string_view) const = 0; @@ -77,7 +77,7 @@ namespace IceSpider { [[nodiscard]] T getURLParam(unsigned int n) const { - return *getFrom(n, &IHttpRequest::getURLParamStr); + return convert(getURLParamStr(n)); } template diff --git a/icespider/unittests/testPerf.cpp b/icespider/unittests/testPerf.cpp index 04e5deb..215ea46 100644 --- a/icespider/unittests/testPerf.cpp +++ b/icespider/unittests/testPerf.cpp @@ -102,6 +102,15 @@ BENCHMARK_F(CoreFixture, get_query_string_param_int)(benchmark::State & state) } } +BENCHMARK_F(CoreFixture, get_url_param)(benchmark::State & state) +{ + CharPtrPtrArray env(rootDir / "fixtures/env1"); + TestRequest r(this, env); + for (auto _ : state) { + benchmark::DoNotOptimize(r.getURLParam(0)); + } +} + BENCHMARK_F(CoreFixture, get_cookie_param)(benchmark::State & state) { CharPtrPtrArray env(rootDir / "fixtures/env1"); -- cgit v1.2.3