From 34c6179bb9d46ad55eecc32b1f129c1538060f35 Mon Sep 17 00:00:00 2001 From: Tingyu Huang Date: Mon, 29 Jan 2018 19:36:56 +0000 Subject: [PATCH] Refine IsContainFields function - Avoid copying fields. - Pass the content by const referenceas to handle const string parameter. Copy it in the function by to_lower_copy. - Declare as a static member function to avoid passing 'this' pointer. Signed-off-by: Tingyu Huang --- include/http.h | 2 +- src/http.cc | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/http.h b/include/http.h index 2c85b6a..b3548a6 100644 --- a/include/http.h +++ b/include/http.h @@ -25,7 +25,7 @@ class Http { static const std::vector passwdFields; static const std::vector sessionFields; - bool IsContainFields(std::string content, std::vector fields); + static bool IsContainFields(const std::string &content, const std::vector &fields); std::string method_; std::string path_; diff --git a/src/http.cc b/src/http.cc index 0a34f6f..b1cba7d 100644 --- a/src/http.cc +++ b/src/http.cc @@ -45,11 +45,11 @@ bool Http::IsCredz() IsContainFields(cookie_, sessionFields); } -bool Http::IsContainFields(string content, vector fields) +bool Http::IsContainFields(const string &content, const vector &fields) { - boost::algorithm::to_lower(content); - for (auto &field : fields) { - if (string::npos != content.find(field)) { + auto lower_content = boost::to_lower_copy(content); + for (const auto &field : fields) { + if (string::npos != lower_content.find(field)) { return true; } }