From 19c390aa54220d7b96889cfe11a264311a15e078 Mon Sep 17 00:00:00 2001 From: flamingcow Date: Thu, 9 May 2019 19:49:05 -0700 Subject: [PATCH] Don't copy params --- request.cc | 4 ++-- request.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/request.cc b/request.cc index 8b40b83..97d9b72 100644 --- a/request.cc +++ b/request.cc @@ -40,10 +40,10 @@ void Request::SetBody(const std::string_view& body) { body_ = body; } -const std::string& Request::GetParam(const std::string& key) { +const std::string_view& Request::GetParam(const std::string& key) { auto iter = params_.find(key); if (iter == params_.end()) { - static const std::string none; + static const std::string_view none; return none; } return iter->second; diff --git a/request.h b/request.h index e078c19..a9fa19b 100644 --- a/request.h +++ b/request.h @@ -21,7 +21,7 @@ class Request { void AddParam(const std::string_view& key, const std::string_view& value); void SetBody(const std::string_view& in); - const std::string& GetParam(const std::string& key); + const std::string_view& GetParam(const std::string& key); const std::string_view& GetBody(); void WriteHeader(const std::string_view& name, const std::string_view& value); @@ -36,7 +36,7 @@ class Request { Connection *conn_; uint16_t request_id_ = 0; - std::unordered_map params_; + std::unordered_map params_; std::string_view body_; firebuf::Buffer out_buf_;