Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(954)

Side by Side Diff: net/spdy/core/spdy_pinnable_buffer_piece.cc

Issue 2840563003: Implement SpdyMakeUnique and SpdyWrapUnique. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
8
7 namespace net { 9 namespace net {
8 10
9 SpdyPinnableBufferPiece::SpdyPinnableBufferPiece() 11 SpdyPinnableBufferPiece::SpdyPinnableBufferPiece()
10 : buffer_(0), length_(0) {} 12 : buffer_(0), length_(0) {}
11 13
12 SpdyPinnableBufferPiece::~SpdyPinnableBufferPiece() {} 14 SpdyPinnableBufferPiece::~SpdyPinnableBufferPiece() {}
13 15
14 void SpdyPinnableBufferPiece::Pin() { 16 void SpdyPinnableBufferPiece::Pin() {
15 if (!storage_ && buffer_ != NULL && length_ != 0) { 17 if (!storage_ && buffer_ != NULL && length_ != 0) {
16 storage_.reset(new char[length_]); 18 storage_.reset(new char[length_]);
17 std::copy(buffer_, buffer_ + length_, storage_.get()); 19 std::copy(buffer_, buffer_ + length_, storage_.get());
18 buffer_ = storage_.get(); 20 buffer_ = storage_.get();
19 } 21 }
20 } 22 }
21 23
22 void SpdyPinnableBufferPiece::Swap(SpdyPinnableBufferPiece* other) { 24 void SpdyPinnableBufferPiece::Swap(SpdyPinnableBufferPiece* other) {
23 size_t length = length_; 25 size_t length = length_;
24 length_ = other->length_; 26 length_ = other->length_;
25 other->length_ = length; 27 other->length_ = length;
26 28
27 const char* buffer = buffer_; 29 const char* buffer = buffer_;
28 buffer_ = other->buffer_; 30 buffer_ = other->buffer_;
29 other->buffer_ = buffer; 31 other->buffer_ = buffer;
30 32
31 storage_.swap(other->storage_); 33 storage_.swap(other->storage_);
32 } 34 }
33 35
34 } // namespace net 36 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/core/spdy_header_indexing_test.cc ('k') | net/spdy/core/spdy_prefixed_buffer_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698