Skip to content

Commit ac7cef2

Browse files
mgerhardymrtazz
authored andcommitted
Small optimizations
use std::move in c++11 mode pass by reference to prevent string copy use char in find_first_of (no length evaluation needed) closes mrtazz#65
1 parent 143f355 commit ac7cef2

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

include/restclient-cpp/connection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class Connection {
104104
} Info;
105105

106106

107-
explicit Connection(const std::string baseUrl);
107+
explicit Connection(const std::string& baseUrl);
108108
~Connection();
109109

110110
// Instance configuration methods

source/connection.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <iostream>
1414
#include <map>
1515
#include <stdexcept>
16+
#include <utility>
1617

1718
#include "restclient-cpp/restclient.h"
1819
#include "restclient-cpp/helpers.h"
@@ -24,7 +25,7 @@
2425
* @param baseUrl - base URL for the connection to use
2526
*
2627
*/
27-
RestClient::Connection::Connection(const std::string baseUrl)
28+
RestClient::Connection::Connection(const std::string& baseUrl)
2829
: lastRequest(), headerFields() {
2930
this->curlHandle = curl_easy_init();
3031
if (!this->curlHandle) {
@@ -84,7 +85,11 @@ RestClient::Connection::AppendHeader(const std::string& key,
8485
*/
8586
void
8687
RestClient::Connection::SetHeaders(RestClient::HeaderFields headers) {
88+
#if __cplusplus >= 201103L
89+
this->headerFields = std::move(headers);
90+
#else
8791
this->headerFields = headers;
92+
#endif
8893
}
8994

9095
/**

source/helpers.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ size_t RestClient::Helpers::header_callback(void *data, size_t size,
4343
RestClient::Response* r;
4444
r = reinterpret_cast<RestClient::Response*>(userdata);
4545
std::string header(reinterpret_cast<char*>(data), size*nmemb);
46-
size_t seperator = header.find_first_of(":");
46+
size_t seperator = header.find_first_of(':');
4747
if ( std::string::npos == seperator ) {
4848
// roll with non seperated headers...
4949
trim(header);

0 commit comments

Comments
 (0)