| OLD | NEW |
| (Empty) | |
| 1 #include "net/spdy/hpack_header_table.h" |
| 2 |
| 3 #include "base/logging.h" |
| 4 #include "net/spdy/hpack_string_util.h" |
| 5 |
| 6 namespace net { |
| 7 |
| 8 HpackHeaderTable::HpackHeaderTable() : size_(0), max_size_(4096) {} |
| 9 |
| 10 HpackHeaderTable::~HpackHeaderTable() {} |
| 11 |
| 12 uint32 HpackHeaderTable::GetEntryCount() const { |
| 13 size_t size = entries_.size(); |
| 14 DCHECK_LE(size, kuint32max); |
| 15 return static_cast<uint32>(size); |
| 16 } |
| 17 |
| 18 const HpackEntry& HpackHeaderTable::GetEntry(uint32 index) const { |
| 19 CHECK_LT(index, GetEntryCount()); |
| 20 return entries_[index]; |
| 21 } |
| 22 |
| 23 HpackEntry* HpackHeaderTable::GetMutableEntry(uint32 index) { |
| 24 CHECK_LT(index, GetEntryCount()); |
| 25 return &entries_[index]; |
| 26 } |
| 27 |
| 28 void HpackHeaderTable::SetMaxSize(uint32 max_size) { |
| 29 max_size_ = max_size; |
| 30 while (size_ > max_size_) { |
| 31 CHECK(!entries_.empty()); |
| 32 size_ -= entries_.back().Size(); |
| 33 entries_.pop_back(); |
| 34 } |
| 35 } |
| 36 |
| 37 void HpackHeaderTable::TryAddEntry( |
| 38 const HpackEntry& entry, |
| 39 int32* index, |
| 40 std::vector<uint32>* removed_referenced_indices) { |
| 41 *index = -1; |
| 42 removed_referenced_indices->clear(); |
| 43 |
| 44 // The algorithm used here is described in 3.3.3. We're assuming |
| 45 // that the given entry is caching the name/value. |
| 46 size_t target_size = 0; |
| 47 size_t size_t_max_size = static_cast<size_t>(max_size_); |
| 48 if (entry.Size() <= size_t_max_size) { |
| 49 // The conditional implies the difference can fit in 32 bits. |
| 50 target_size = size_t_max_size - entry.Size(); |
| 51 } |
| 52 while ((static_cast<size_t>(size_) > target_size) && !entries_.empty()) { |
| 53 if (entries_.back().IsReferenced()) { |
| 54 removed_referenced_indices->push_back(entries_.size() - 1); |
| 55 } |
| 56 size_ -= entries_.back().Size(); |
| 57 entries_.pop_back(); |
| 58 } |
| 59 |
| 60 if (entry.Size() <= size_t_max_size) { |
| 61 // Implied by the exit condition of the while loop above and the |
| 62 // condition of the if. |
| 63 DCHECK_LE(static_cast<size_t>(size_) + entry.Size(), size_t_max_size); |
| 64 size_ += entry.Size(); |
| 65 *index = 0; |
| 66 entries_.push_front(entry); |
| 67 } |
| 68 } |
| 69 |
| 70 } // namespace net |
| OLD | NEW |