summaryrefslogtreecommitdiffstats
path: root/net/spdy/spdy_pinnable_buffer_piece.cc
blob: 01f8d1db1436b358686fb28c6ce1537b74d1ab9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/spdy/spdy_pinnable_buffer_piece.h"

namespace net {

SpdyPinnableBufferPiece::SpdyPinnableBufferPiece()
    : buffer_(0), length_(0) {}

SpdyPinnableBufferPiece::~SpdyPinnableBufferPiece() {}

void SpdyPinnableBufferPiece::Pin() {
  if (!storage_ && buffer_ != NULL && length_ != 0) {
    storage_.reset(new char[length_]);
    std::copy(buffer_, buffer_ + length_, storage_.get());
    buffer_ = storage_.get();
  }
}

void SpdyPinnableBufferPiece::Swap(SpdyPinnableBufferPiece* other) {
  size_t length = length_;
  length_ = other->length_;
  other->length_ = length;

  const char* buffer = buffer_;
  buffer_ = other->buffer_;
  other->buffer_ = buffer;

  storage_.swap(other->storage_);
}

}  // namespace net