| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/spdy_header_block.h" | 5 #include "net/spdy/spdy_header_block.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <ios> | 8 #include <ios> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 return *this; | 113 return *this; |
| 114 } | 114 } |
| 115 | 115 |
| 116 SpdyHeaderBlock::StringPieceProxy::operator StringPiece() const { | 116 SpdyHeaderBlock::StringPieceProxy::operator StringPiece() const { |
| 117 return (lookup_result_ == block_->end()) ? StringPiece() | 117 return (lookup_result_ == block_->end()) ? StringPiece() |
| 118 : lookup_result_->second; | 118 : lookup_result_->second; |
| 119 } | 119 } |
| 120 | 120 |
| 121 SpdyHeaderBlock::SpdyHeaderBlock() : storage_(new Storage) {} | 121 SpdyHeaderBlock::SpdyHeaderBlock() : storage_(new Storage) {} |
| 122 | 122 |
| 123 SpdyHeaderBlock::SpdyHeaderBlock(const SpdyHeaderBlock& other) | |
| 124 : storage_(new Storage) { | |
| 125 for (auto iter : other) { | |
| 126 AppendHeader(iter.first, iter.second); | |
| 127 } | |
| 128 } | |
| 129 | |
| 130 SpdyHeaderBlock::SpdyHeaderBlock(SpdyHeaderBlock&& other) | 123 SpdyHeaderBlock::SpdyHeaderBlock(SpdyHeaderBlock&& other) |
| 131 : storage_(std::move(other.storage_)) { | 124 : storage_(std::move(other.storage_)) { |
| 132 // |block_| is linked_hash_map, which does not have move constructor. | 125 // |block_| is linked_hash_map, which does not have move constructor. |
| 133 block_.swap(other.block_); | 126 block_.swap(other.block_); |
| 134 } | 127 } |
| 135 | 128 |
| 136 SpdyHeaderBlock::~SpdyHeaderBlock() {} | 129 SpdyHeaderBlock::~SpdyHeaderBlock() {} |
| 137 | 130 |
| 138 SpdyHeaderBlock& SpdyHeaderBlock::operator=(const SpdyHeaderBlock& other) { | |
| 139 clear(); | |
| 140 for (auto iter : other) { | |
| 141 AppendHeader(iter.first, iter.second); | |
| 142 } | |
| 143 return *this; | |
| 144 } | |
| 145 | |
| 146 SpdyHeaderBlock& SpdyHeaderBlock::operator=(SpdyHeaderBlock&& other) { | 131 SpdyHeaderBlock& SpdyHeaderBlock::operator=(SpdyHeaderBlock&& other) { |
| 147 storage_ = std::move(other.storage_); | 132 storage_ = std::move(other.storage_); |
| 148 // |block_| is linked_hash_map, which does not have move assignment | 133 // |block_| is linked_hash_map, which does not have move assignment |
| 149 // operator. | 134 // operator. |
| 150 block_.swap(other.block_); | 135 block_.swap(other.block_); |
| 151 return *this; | 136 return *this; |
| 152 } | 137 } |
| 153 | 138 |
| 139 SpdyHeaderBlock SpdyHeaderBlock::Clone() const { |
| 140 SpdyHeaderBlock copy; |
| 141 for (auto iter : *this) { |
| 142 copy.AppendHeader(iter.first, iter.second); |
| 143 } |
| 144 return copy; |
| 145 } |
| 146 |
| 154 bool SpdyHeaderBlock::operator==(const SpdyHeaderBlock& other) const { | 147 bool SpdyHeaderBlock::operator==(const SpdyHeaderBlock& other) const { |
| 155 return size() == other.size() && std::equal(begin(), end(), other.begin()); | 148 return size() == other.size() && std::equal(begin(), end(), other.begin()); |
| 156 } | 149 } |
| 157 | 150 |
| 158 bool SpdyHeaderBlock::operator!=(const SpdyHeaderBlock& other) const { | 151 bool SpdyHeaderBlock::operator!=(const SpdyHeaderBlock& other) const { |
| 159 return !(operator==(other)); | 152 return !(operator==(other)); |
| 160 } | 153 } |
| 161 | 154 |
| 162 string SpdyHeaderBlock::DebugString() const { | 155 string SpdyHeaderBlock::DebugString() const { |
| 163 if (empty()) { | 156 if (empty()) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 if (!it.value().GetAsString(&value)) { | 252 if (!it.value().GetAsString(&value)) { |
| 260 headers->clear(); | 253 headers->clear(); |
| 261 return false; | 254 return false; |
| 262 } | 255 } |
| 263 (*headers)[it.key()] = value; | 256 (*headers)[it.key()] = value; |
| 264 } | 257 } |
| 265 return true; | 258 return true; |
| 266 } | 259 } |
| 267 | 260 |
| 268 } // namespace net | 261 } // namespace net |
| OLD | NEW |