From 8c7b6199f720f3c67235888848e3a1d35efcd88f Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Thu, 7 Jan 2016 09:16:06 -0300 Subject: [PATCH] Optimization on the tolower function --- src/assay.cc | 7 ++++--- src/utils.cc | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/assay.cc b/src/assay.cc index dae61909..1bcee838 100644 --- a/src/assay.cc +++ b/src/assay.cc @@ -433,12 +433,13 @@ int Assay::addRequestHeader(const std::string& key, this->m_collections.store("REQUEST_HEADERS:" + key, value); - if (tolower(key) == tolower("Authorization")) { + std::string keyl = tolower(key); + if (keyl == "authorization") { std::vector type = split(value, ' '); this->m_collections.store("AUTH_TYPE", type[0]); } - if (tolower(key) == "cookie") { + if (keyl == "cookie") { std::vector cookies = split(value, ';'); while (cookies.empty() == false) { std::vector s = split(cookies.back(), '='); @@ -461,7 +462,7 @@ int Assay::addRequestHeader(const std::string& key, * */ - if (tolower(key) == "content-type") { + if (keyl == "content-type") { std::string multipart("multipart/form-data"); std::string l = tolower(value); diff --git a/src/utils.cc b/src/utils.cc index 21b89310..20842ade 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -25,7 +25,7 @@ #include #include - +#include #include #include #include @@ -126,10 +126,12 @@ void chomp(std::string *str) { std::string tolower(std::string str) { std::locale loc; std::string value; + value.resize(str.length()); - for (std::string::size_type i=0; i < str.length(); ++i) { - value.assign(value + std::tolower(str[i], loc)); - } + std::transform(str.begin(), + str.end(), + value.begin(), + ::tolower); return value; }