| 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 <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 263 |
| 264 void SpdyHeaderBlock::insert(const SpdyHeaderBlock::value_type& value) { | 264 void SpdyHeaderBlock::insert(const SpdyHeaderBlock::value_type& value) { |
| 265 // TODO(birenroy): Write new value in place of old value, if it fits. | 265 // TODO(birenroy): Write new value in place of old value, if it fits. |
| 266 auto iter = block_.find(value.first); | 266 auto iter = block_.find(value.first); |
| 267 if (iter == block_.end()) { | 267 if (iter == block_.end()) { |
| 268 DVLOG(1) << "Inserting: (" << value.first << ", " << value.second << ")"; | 268 DVLOG(1) << "Inserting: (" << value.first << ", " << value.second << ")"; |
| 269 AppendHeader(value.first, value.second); | 269 AppendHeader(value.first, value.second); |
| 270 } else { | 270 } else { |
| 271 DVLOG(1) << "Updating key: " << iter->first | 271 DVLOG(1) << "Updating key: " << iter->first |
| 272 << " with value: " << value.second; | 272 << " with value: " << value.second; |
| 273 auto storage = GetStorage(); | 273 auto* storage = GetStorage(); |
| 274 iter->second = | 274 iter->second = |
| 275 HeaderValue(storage, iter->first, storage->Write(value.second)); | 275 HeaderValue(storage, iter->first, storage->Write(value.second)); |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 | 278 |
| 279 SpdyHeaderBlock::ValueProxy SpdyHeaderBlock::operator[](const StringPiece key) { | 279 SpdyHeaderBlock::ValueProxy SpdyHeaderBlock::operator[](const StringPiece key) { |
| 280 DVLOG(2) << "Operator[] saw key: " << key; | 280 DVLOG(2) << "Operator[] saw key: " << key; |
| 281 StringPiece out_key; | 281 StringPiece out_key; |
| 282 auto iter = block_.find(key); | 282 auto iter = block_.find(key); |
| 283 if (iter == block_.end()) { | 283 if (iter == block_.end()) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 306 } | 306 } |
| 307 | 307 |
| 308 size_t SpdyHeaderBlock::EstimateMemoryUsage() const { | 308 size_t SpdyHeaderBlock::EstimateMemoryUsage() const { |
| 309 // TODO(xunjieli): https://crbug.com/669108. Also include |block_| when EMU() | 309 // TODO(xunjieli): https://crbug.com/669108. Also include |block_| when EMU() |
| 310 // supports linked_hash_map. | 310 // supports linked_hash_map. |
| 311 return SpdyEstimateMemoryUsage(storage_); | 311 return SpdyEstimateMemoryUsage(storage_); |
| 312 } | 312 } |
| 313 | 313 |
| 314 void SpdyHeaderBlock::AppendHeader(const StringPiece key, | 314 void SpdyHeaderBlock::AppendHeader(const StringPiece key, |
| 315 const StringPiece value) { | 315 const StringPiece value) { |
| 316 auto storage = GetStorage(); | 316 auto* storage = GetStorage(); |
| 317 auto backed_key = storage->Write(key); | 317 auto backed_key = storage->Write(key); |
| 318 block_.emplace(make_pair( | 318 block_.emplace(make_pair( |
| 319 backed_key, HeaderValue(storage, backed_key, storage->Write(value)))); | 319 backed_key, HeaderValue(storage, backed_key, storage->Write(value)))); |
| 320 } | 320 } |
| 321 | 321 |
| 322 SpdyHeaderBlock::Storage* SpdyHeaderBlock::GetStorage() { | 322 SpdyHeaderBlock::Storage* SpdyHeaderBlock::GetStorage() { |
| 323 if (!storage_) { | 323 if (!storage_) { |
| 324 storage_.reset(new Storage); | 324 storage_.reset(new Storage); |
| 325 } | 325 } |
| 326 return storage_.get(); | 326 return storage_.get(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 return storage_->bytes_allocated(); | 375 return storage_->bytes_allocated(); |
| 376 } | 376 } |
| 377 } | 377 } |
| 378 | 378 |
| 379 size_t Join(char* dst, | 379 size_t Join(char* dst, |
| 380 const std::vector<StringPiece>& fragments, | 380 const std::vector<StringPiece>& fragments, |
| 381 StringPiece separator) { | 381 StringPiece separator) { |
| 382 if (fragments.empty()) { | 382 if (fragments.empty()) { |
| 383 return 0; | 383 return 0; |
| 384 } | 384 } |
| 385 auto original_dst = dst; | 385 auto* original_dst = dst; |
| 386 auto it = fragments.begin(); | 386 auto it = fragments.begin(); |
| 387 memcpy(dst, it->data(), it->size()); | 387 memcpy(dst, it->data(), it->size()); |
| 388 dst += it->size(); | 388 dst += it->size(); |
| 389 for (++it; it != fragments.end(); ++it) { | 389 for (++it; it != fragments.end(); ++it) { |
| 390 memcpy(dst, separator.data(), separator.size()); | 390 memcpy(dst, separator.data(), separator.size()); |
| 391 dst += separator.size(); | 391 dst += separator.size(); |
| 392 memcpy(dst, it->data(), it->size()); | 392 memcpy(dst, it->data(), it->size()); |
| 393 dst += it->size(); | 393 dst += it->size(); |
| 394 } | 394 } |
| 395 return dst - original_dst; | 395 return dst - original_dst; |
| 396 } | 396 } |
| 397 | 397 |
| 398 } // namespace net | 398 } // namespace net |
| OLD | NEW |