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