• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 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 "quiche/spdy/core/spdy_pinnable_buffer_piece.h"
6 
7 #include <algorithm>
8 #include <cstddef>
9 
10 namespace spdy {
11 
SpdyPinnableBufferPiece()12 SpdyPinnableBufferPiece::SpdyPinnableBufferPiece()
13     : buffer_(nullptr), length_(0) {}
14 
15 SpdyPinnableBufferPiece::~SpdyPinnableBufferPiece() = default;
16 
Pin()17 void SpdyPinnableBufferPiece::Pin() {
18   if (!storage_ && buffer_ != nullptr && length_ != 0) {
19     storage_.reset(new char[length_]);
20     std::copy(buffer_, buffer_ + length_, storage_.get());
21     buffer_ = storage_.get();
22   }
23 }
24 
Swap(SpdyPinnableBufferPiece * other)25 void SpdyPinnableBufferPiece::Swap(SpdyPinnableBufferPiece* other) {
26   size_t length = length_;
27   length_ = other->length_;
28   other->length_ = length;
29 
30   const char* buffer = buffer_;
31   buffer_ = other->buffer_;
32   other->buffer_ = buffer;
33 
34   storage_.swap(other->storage_);
35 }
36 
37 }  // namespace spdy
38