1
0
Fork 0
mirror of https://github.com/KingDuckZ/incredis synced 2025-08-11 13:09:48 +00:00

Optimization - Get rid of the vector that held the unique_ptr.

Use the replies list directly. I can't see any significant
performance improvement yet, but there is something else I want to
try starting from this point.
This commit is contained in:
King_DuckZ 2016-12-06 18:39:41 +00:00
parent 093d1dd198
commit a6fab83296
8 changed files with 192 additions and 33 deletions

View file

@ -20,8 +20,9 @@
#include "reply.hpp"
#include "arg_to_bin_safe.hpp"
#include <vector>
#include "sized_range.hpp"
#include <memory>
#include <forward_list>
namespace redis {
class Command;
@ -31,12 +32,15 @@ namespace redis {
class Batch {
friend class Command;
public:
using ConstReplies = SizedRange<std::forward_list<Reply>::const_iterator>;
using Replies = SizedRange<std::forward_list<Reply>::iterator>;
Batch ( Batch&& parOther );
Batch ( const Batch& ) = delete;
~Batch ( void ) noexcept;
const std::vector<Reply>& replies ( void );
std::vector<Reply>& replies_nonconst ( void );
ConstReplies replies ( void ) const;
Replies replies_nonconst ( void );
bool replies_requested ( void ) const;
void throw_if_failed ( void );
@ -54,8 +58,6 @@ namespace redis {
explicit Batch ( AsyncConnection* parConn, ThreadContext& parThreadContext );
void run_pvt ( int parArgc, const char** parArgv, std::size_t* parLengths );
std::vector<std::unique_ptr<Reply>> m_futures;
std::vector<Reply> m_replies;
std::unique_ptr<LocalData> m_local_data;
AsyncConnection* m_async_conn;
};

View file

@ -27,6 +27,8 @@
namespace redis {
class IncRedisBatch {
public:
using ConstReplies = Batch::ConstReplies;
enum ZADD_Mode {
ZADD_XX_UpdateOnly,
ZADD_NX_AlwaysAdd,
@ -46,7 +48,7 @@ namespace redis {
void reset ( void );
void throw_if_failed ( void );
const std::vector<Reply>& replies ( void ) { return m_batch.replies(); }
ConstReplies replies ( void ) { return m_batch.replies(); }
Batch& batch ( void ) { return m_batch; }
const Batch& batch ( void ) const { return m_batch; }

View file

@ -0,0 +1,56 @@
/* Copyright 2016, Michele Santullo
* This file is part of "incredis".
*
* "incredis" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "incredis" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "incredis". If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef idC3909E193A3C4DBEB9B646A4F5ED3518
#define idC3909E193A3C4DBEB9B646A4F5ED3518
#include <boost/range/iterator_range_core.hpp>
#include <cstddef>
#include <cassert>
#include <ciso646>
namespace redis {
template <typename I>
class SizedRange : public boost::iterator_range<I> {
public:
SizedRange ( I parBegin, I parEnd, std::size_t parSize ) :
boost::iterator_range<I>(parBegin, parEnd),
m_size(parSize)
{
}
template <typename R>
SizedRange ( R& parRange, std::size_t parSize ) :
boost::iterator_range<I>(parRange),
m_size(parSize)
{
}
~SizedRange ( void ) noexcept = default;
std::size_t size ( void ) const { return m_size; }
bool empty ( void ) const { return static_cast<bool>(0 == m_size); }
typename I::reference front ( void ) { assert(not empty()); return *this->begin(); }
const typename I::reference front ( void ) const { assert(not empty()); return *this->begin(); }
private:
std::size_t m_size;
};
} //namespace redis
#endif