Skip to content

Commit 0979e94

Browse files
pmelkozerdrewdzzz
authored andcommitted
client: use std::string_view for call function
For most of cases encoding fuction such as `call`, `execute` and `prepare` use predefined fixed literal. Those values are best to be expressed as std::string_view literals. std::string_view are really usefull and can be easily createad from any sequense memory areas. There are no changes are required from cliend side as std::string_view can be implicilty coverted from std::string.
1 parent f7c9450 commit 0979e94

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/Client/Connection.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#include <sys/uio.h> //iovec
3939
#include <string>
40+
#include <string_view>
4041
#include <unordered_map> //futures
4142

4243
/** rid == request id */
@@ -175,7 +176,7 @@ class Connection
175176
size_t getFutureCount() const;
176177

177178
template <class T>
178-
rid_t call(const std::string &func, const T &args);
179+
rid_t call(std::string_view func, const T &args);
179180
rid_t ping();
180181

181182
/**
@@ -185,7 +186,7 @@ class Connection
185186
* @retval request id
186187
*/
187188
template <class T>
188-
rid_t execute(const std::string& statement, const T& parameters);
189+
rid_t execute(std::string_view statement, const T& parameters);
189190

190191
/**
191192
* Execute the SQL statement contained in the 'statement' parameter.
@@ -203,7 +204,7 @@ class Connection
203204
* @param statement statement, which should conform to the rules for SQL grammar
204205
* @retval request id
205206
*/
206-
rid_t prepare(const std::string& statement);
207+
rid_t prepare(std::string_view statement);
207208

208209
void setError(const std::string &msg, int errno_ = 0);
209210
bool hasError() const;
@@ -606,7 +607,7 @@ decodeGreeting(Connection<BUFFER, NetProvider> &conn)
606607
template<class BUFFER, class NetProvider>
607608
template <class T>
608609
rid_t
609-
Connection<BUFFER, NetProvider>::execute(const std::string& statement, const T& parameters)
610+
Connection<BUFFER, NetProvider>::execute(std::string_view statement, const T& parameters)
610611
{
611612
impl->enc.encodeExecute(statement, parameters);
612613
impl->connector.readyToSend(*this);
@@ -625,7 +626,7 @@ Connection<BUFFER, NetProvider>::execute(unsigned int stmt_id, const T& paramete
625626

626627
template<class BUFFER, class NetProvider>
627628
rid_t
628-
Connection<BUFFER, NetProvider>::prepare(const std::string& statement)
629+
Connection<BUFFER, NetProvider>::prepare(std::string_view statement)
629630
{
630631
impl->enc.encodePrepare(statement);
631632
impl->connector.readyToSend(*this);
@@ -635,7 +636,7 @@ Connection<BUFFER, NetProvider>::prepare(const std::string& statement)
635636
template<class BUFFER, class NetProvider>
636637
template <class T>
637638
rid_t
638-
Connection<BUFFER, NetProvider>::call(const std::string &func, const T &args)
639+
Connection<BUFFER, NetProvider>::call(std::string_view func, const T &args)
639640
{
640641
impl->enc.encodeCall(func, args);
641642
impl->connector.readyToSend(*this);

src/Client/RequestEncoder.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <any>
3333
#include <cstdint>
3434
#include <map>
35+
#include <string_view>
3536

3637
#include "IprotoConstants.hpp"
3738
#include "ResponseReader.hpp"
@@ -85,12 +86,12 @@ class RequestEncoder {
8586
uint32_t limit = UINT32_MAX, uint32_t offset = 0,
8687
IteratorType iterator = EQ);
8788
template <class T>
88-
size_t encodeExecute(const std::string& statement, const T& parameters);
89+
size_t encodeExecute(std::string_view statement, const T& parameters);
8990
template <class T>
9091
size_t encodeExecute(unsigned int stmt_id, const T& parameters);
91-
size_t encodePrepare(const std::string& statement);
92+
size_t encodePrepare(std::string_view statement);
9293
template <class T>
93-
size_t encodeCall(const std::string &func, const T &args);
94+
size_t encodeCall(std::string_view func, const T &args);
9495
size_t encodeAuth(std::string_view user, std::string_view passwd,
9596
const Greeting &greet);
9697
void reencodeAuth(std::string_view user, std::string_view passwd,
@@ -256,7 +257,7 @@ RequestEncoder<BUFFER>::encodeSelect(const T &key,
256257
template<class BUFFER>
257258
template <class T>
258259
size_t
259-
RequestEncoder<BUFFER>::encodeExecute(const std::string& statement, const T& parameters)
260+
RequestEncoder<BUFFER>::encodeExecute(std::string_view statement, const T& parameters)
260261
{
261262
iterator_t<BUFFER> request_start = m_Buf.end();
262263
m_Buf.write('\xce');
@@ -293,7 +294,7 @@ RequestEncoder<BUFFER>::encodeExecute(unsigned int stmt_id, const T& parameters)
293294

294295
template<class BUFFER>
295296
size_t
296-
RequestEncoder<BUFFER>::encodePrepare(const std::string& statement)
297+
RequestEncoder<BUFFER>::encodePrepare(std::string_view statement)
297298
{
298299
iterator_t<BUFFER> request_start = m_Buf.end();
299300
m_Buf.write('\xce');
@@ -310,7 +311,7 @@ RequestEncoder<BUFFER>::encodePrepare(const std::string& statement)
310311
template<class BUFFER>
311312
template <class T>
312313
size_t
313-
RequestEncoder<BUFFER>::encodeCall(const std::string &func, const T &args)
314+
RequestEncoder<BUFFER>::encodeCall(std::string_view func, const T &args)
314315
{
315316
iterator_t<BUFFER> request_start = m_Buf.end();
316317
m_Buf.write('\xce');

0 commit comments

Comments
 (0)