blob: 8670962c56a1e44940f2e632a43012bef6ae121b [file] [log] [blame]
QUICHE team82dee2f2019-01-18 12:35:12 -05001// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "net/third_party/quiche/src/spdy/core/spdy_pinnable_buffer_piece.h"
6
7#include <new>
8
9namespace spdy {
10
11SpdyPinnableBufferPiece::SpdyPinnableBufferPiece()
12 : buffer_(nullptr), length_(0) {}
13
14SpdyPinnableBufferPiece::~SpdyPinnableBufferPiece() = default;
15
16void SpdyPinnableBufferPiece::Pin() {
17 if (!storage_ && buffer_ != nullptr && length_ != 0) {
18 storage_.reset(new char[length_]);
19 std::copy(buffer_, buffer_ + length_, storage_.get());
20 buffer_ = storage_.get();
21 }
22}
23
24void SpdyPinnableBufferPiece::Swap(SpdyPinnableBufferPiece* other) {
25 size_t length = length_;
26 length_ = other->length_;
27 other->length_ = length;
28
29 const char* buffer = buffer_;
30 buffer_ = other->buffer_;
31 other->buffer_ = buffer;
32
33 storage_.swap(other->storage_);
34}
35
36} // namespace spdy