diff --git a/src/oro/api_nap.cpp b/src/oro/api_nap.cpp index 2a2889a..a7be2fc 100644 --- a/src/oro/api_nap.cpp +++ b/src/oro/api_nap.cpp @@ -30,7 +30,7 @@ Header to_header (const nap::HttpResponse& resp) { Header ret; for (const auto& entry : resp.header) { if (entry.first == "Date") - ret.date = from_header_timestamp(entry.second); + ret.date = from_header_timestamp(std::string(entry.second)); else if (entry.first == "X-RateLimit-Limit") ret.rate_limit = int_conv(entry.second); else if (entry.first == "X-RateLimit-Remaining") diff --git a/src/oro/datatypes.cpp b/src/oro/datatypes.cpp index 5e7da46..b2c66f4 100644 --- a/src/oro/datatypes.cpp +++ b/src/oro/datatypes.cpp @@ -22,8 +22,8 @@ #include "date/date.h" namespace oro { - Timestamp& Timestamp::operator= (const std::string& str) { - ts = from_json_timestamp(str); + Timestamp& Timestamp::operator= (std::string&& str) { + ts = from_json_timestamp(std::move(str)); return *this; } diff --git a/src/oro/datatypes.hpp b/src/oro/datatypes.hpp index 8edccd9..8a18b09 100644 --- a/src/oro/datatypes.hpp +++ b/src/oro/datatypes.hpp @@ -25,7 +25,7 @@ namespace oro { typedef std::chrono::time_point timestamp_t; struct Timestamp { - Timestamp& operator= (const std::string& str); + Timestamp& operator= (std::string&& str); operator timestamp_t() const { return ts; } timestamp_t ts; diff --git a/src/oro/private/dateconv.cpp b/src/oro/private/dateconv.cpp index 911ad1e..5a223f7 100644 --- a/src/oro/private/dateconv.cpp +++ b/src/oro/private/dateconv.cpp @@ -32,8 +32,8 @@ namespace { } }; - Timestamp to_timestamp (const char* fmt, std::string_view str) { - std::istringstream iss{std::string(str)}; + Timestamp to_timestamp (const char* fmt, std::string&& str) { + std::istringstream iss{std::move(str)}; Timestamp ts; date::from_stream(iss, fmt, ts.ts); return ts; @@ -45,29 +45,25 @@ namespace { //For formatting modifiers see: //https://howardhinnant.github.io/date/date.html#from_stream_formatting -Timestamp from_json_timestamp (const std::string& str) { +Timestamp from_json_timestamp (std::string&& str) { if (not str.empty() and str.back() == 'Z') { //date has this format: 2020-06-19T22:40:51Z - return to_timestamp("%FT%TZ", str); + return to_timestamp("%FT%TZ", std::move(str)); } else { //date has this format: 2020-06-19T22:33:36.855672+00:00 - return to_timestamp("%FT%T%Ez", str); + return to_timestamp("%FT%T%Ez", std::move(str)); } } -Timestamp from_header_timestamp (const std::string& str) { - return from_header_timestamp(std::string_view(str)); -} - -Timestamp from_header_timestamp (std::string_view str) { +Timestamp from_header_timestamp (std::string&& str) { UniqueLocale loc(std::setlocale(LC_TIME, "POSIX")); //date has this format: Fri, 19 Jun 2020 22:33:43 GMT - return to_timestamp("%a, %d %b %Y %T %Z", str); + return to_timestamp("%a, %d %b %Y %T %Z", std::move(str)); } -Timestamp from_sqlite_timestamp (const std::string& str) { - return to_timestamp("%F %T", str); +Timestamp from_sqlite_timestamp (std::string&& str) { + return to_timestamp("%F %T", std::move(str)); } std::string to_sqlite_string (const oro::Timestamp& ts) { diff --git a/src/oro/private/dateconv.hpp b/src/oro/private/dateconv.hpp index 361f137..33ca1b7 100644 --- a/src/oro/private/dateconv.hpp +++ b/src/oro/private/dateconv.hpp @@ -19,13 +19,11 @@ #include "oro/datatypes.hpp" #include -#include namespace oro { -Timestamp from_json_timestamp (const std::string& str); -Timestamp from_header_timestamp (std::string_view str); -Timestamp from_header_timestamp (const std::string& str); -Timestamp from_sqlite_timestamp (const std::string& str); +Timestamp from_json_timestamp (std::string&& str); +Timestamp from_header_timestamp (std::string&& str); +Timestamp from_sqlite_timestamp (std::string&& str); std::string to_sqlite_string (const Timestamp& ts); std::string to_iso8601_string (const Timestamp& ts); } //namespace oro diff --git a/src/oro/private/originsdb_sqlite.cpp b/src/oro/private/originsdb_sqlite.cpp index 4fff2c7..94baa81 100644 --- a/src/oro/private/originsdb_sqlite.cpp +++ b/src/oro/private/originsdb_sqlite.cpp @@ -556,7 +556,7 @@ Timestamp OriginsDBSQLite::next_access_time (DBOperation op) const { if (not info) throw std::runtime_error("Query returned no value for access.operation " + to_string(static_cast(op))); - return from_sqlite_timestamp(*info); + return from_sqlite_timestamp(std::move(*info)); } } //namespace oro