| 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/hpack_entry.h" | 5 #include "net/spdy/hpack_entry.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "net/spdy/hpack_string_util.h" | 9 #include "net/spdy/hpack_string_util.h" |
| 10 | 10 |
| 11 namespace net { | 11 namespace net { |
| 12 | 12 |
| 13 using base::StringPiece; | 13 using base::StringPiece; |
| 14 | 14 |
| 15 const size_t HpackEntry::kSizeOverhead = 32; | 15 const size_t HpackEntry::kSizeOverhead = 32; |
| 16 | 16 |
| 17 bool HpackEntry::Comparator::operator() ( | 17 bool HpackEntry::Comparator::operator()(const HpackEntry* lhs, |
| 18 const HpackEntry* lhs, const HpackEntry* rhs) const { | 18 const HpackEntry* rhs) const { |
| 19 int result = lhs->name().compare(rhs->name()); | 19 int result = lhs->name().compare(rhs->name()); |
| 20 if (result != 0) | 20 if (result != 0) |
| 21 return result < 0; | 21 return result < 0; |
| 22 result = lhs->value().compare(rhs->value()); | 22 result = lhs->value().compare(rhs->value()); |
| 23 if (result != 0) | 23 if (result != 0) |
| 24 return result < 0; | 24 return result < 0; |
| 25 DCHECK(lhs == rhs || lhs->Index() != rhs->Index()); | 25 DCHECK(lhs == rhs || lhs->Index() != rhs->Index()); |
| 26 return lhs->Index() < rhs->Index(); | 26 return lhs->Index() < rhs->Index(); |
| 27 } | 27 } |
| 28 | 28 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 50 total_insertions_or_size_(NULL) { | 50 total_insertions_or_size_(NULL) { |
| 51 } | 51 } |
| 52 | 52 |
| 53 HpackEntry::HpackEntry() | 53 HpackEntry::HpackEntry() |
| 54 : is_static_(false), | 54 : is_static_(false), |
| 55 state_(0), | 55 state_(0), |
| 56 insertion_index_(0), | 56 insertion_index_(0), |
| 57 total_insertions_or_size_(NULL) { | 57 total_insertions_or_size_(NULL) { |
| 58 } | 58 } |
| 59 | 59 |
| 60 HpackEntry::~HpackEntry() {} | 60 HpackEntry::~HpackEntry() { |
| 61 } |
| 61 | 62 |
| 62 size_t HpackEntry::Index() const { | 63 size_t HpackEntry::Index() const { |
| 63 if (total_insertions_or_size_ == NULL) { | 64 if (total_insertions_or_size_ == NULL) { |
| 64 // This is a lookup instance. | 65 // This is a lookup instance. |
| 65 return 0; | 66 return 0; |
| 66 } else if (IsStatic()) { | 67 } else if (IsStatic()) { |
| 67 return 1 + insertion_index_ + *total_insertions_or_size_; | 68 return 1 + insertion_index_ + *total_insertions_or_size_; |
| 68 } else { | 69 } else { |
| 69 return *total_insertions_or_size_ - insertion_index_; | 70 return *total_insertions_or_size_ - insertion_index_; |
| 70 } | 71 } |
| 71 } | 72 } |
| 72 | 73 |
| 73 // static | 74 // static |
| 74 size_t HpackEntry::Size(StringPiece name, StringPiece value) { | 75 size_t HpackEntry::Size(StringPiece name, StringPiece value) { |
| 75 return name.size() + value.size() + kSizeOverhead; | 76 return name.size() + value.size() + kSizeOverhead; |
| 76 } | 77 } |
| 77 size_t HpackEntry::Size() const { | 78 size_t HpackEntry::Size() const { |
| 78 return Size(name(), value()); | 79 return Size(name(), value()); |
| 79 } | 80 } |
| 80 | 81 |
| 81 std::string HpackEntry::GetDebugString() const { | 82 std::string HpackEntry::GetDebugString() const { |
| 82 return "{ name: \"" + name_ + | 83 return "{ name: \"" + name_ + "\", value: \"" + value_ + "\", " + |
| 83 "\", value: \"" + value_ + | 84 (IsStatic() ? "static" : "dynamic") + ", state: " + |
| 84 "\", " + (IsStatic() ? "static" : "dynamic") + | 85 base::IntToString(state_) + " }"; |
| 85 ", state: " + base::IntToString(state_) + " }"; | |
| 86 } | 86 } |
| 87 | 87 |
| 88 } // namespace net | 88 } // namespace net |
| OLD | NEW |