コード例 #1
0
ファイル: buffer.hpp プロジェクト: nousxiong/resp
  /**
   * @note des first will be reset to ref.
   */
  static void move(buffer& des, buffer& src)
  {
    des.reset();
    if (src.is_ref())
    {
      des.data_ = src.data_;
      des.size_ = src.size_;
    }
    else if (src.is_small())
    {
      des.capacity_ = RESP_SMALL_BUFFER_SIZE;
      des.data_ = des.small_;
      des.size_ = src.size_;
      std::memcpy(des.data_, src.data_, des.size_);
    }
    else
    {
      /// large
      des.capacity_ = src.capacity_;
      des.data_ = src.data_;
      des.size_ = src.size_;
    }

    /// clear src
    src.capacity_ = 0;
    src.data_ = 0;
    src.size_ = 0;
  }
コード例 #2
0
ファイル: buffer.hpp プロジェクト: nousxiong/resp
  /// Copy constructor.
  buffer(buffer const& other)
    : capacity_(other.capacity_)
    , data_(0)
    , size_(other.size_)
  {
    if (other.is_ref())
    {
      data_ = other.data_;
    }
    else if (other.is_small())
    {
      data_ = small_;
    }
    else
    {
      /// large
      data_ = (char*)std::malloc(capacity_);
      if (data_ == 0)
      {
        throw std::bad_alloc();
      }
    }

    if (!is_ref())
    {
      std::memcpy(data_, other.data_, size_);
    }
  }