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

Unified Diff: net/spdy/hpack_header_table.cc

Issue 549583003: Make HPACK static table static and immutable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/spdy/hpack_header_table.h ('k') | net/spdy/hpack_header_table_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/hpack_header_table.cc
diff --git a/net/spdy/hpack_header_table.cc b/net/spdy/hpack_header_table.cc
index 48bf7156ef880a0c6682603f50438fa1ce311661..044c59d74dce5ad6fbfcdcba0b884c0a0901c140 100644
--- a/net/spdy/hpack_header_table.cc
+++ b/net/spdy/hpack_header_table.cc
@@ -8,97 +8,13 @@
#include "base/logging.h"
#include "net/spdy/hpack_constants.h"
+#include "net/spdy/hpack_static_table.h"
#include "net/spdy/hpack_string_util.h"
namespace net {
using base::StringPiece;
-namespace {
-
-// An entry in the static table. Must be a POD in order to avoid
-// static initializers, i.e. no user-defined constructors or
-// destructors.
-struct StaticEntry {
- const char* const name;
- const size_t name_len;
- const char* const value;
- const size_t value_len;
-};
-
-// The "constructor" for a StaticEntry that computes the lengths at
-// compile time.
-#define STATIC_ENTRY(name, value) \
- { name, arraysize(name) - 1, value, arraysize(value) - 1 }
-
-const StaticEntry kStaticTable[] = {
- STATIC_ENTRY(":authority" , ""), // 1
- STATIC_ENTRY(":method" , "GET"), // 2
- STATIC_ENTRY(":method" , "POST"), // 3
- STATIC_ENTRY(":path" , "/"), // 4
- STATIC_ENTRY(":path" , "/index.html"), // 5
- STATIC_ENTRY(":scheme" , "http"), // 6
- STATIC_ENTRY(":scheme" , "https"), // 7
- STATIC_ENTRY(":status" , "200"), // 8
- STATIC_ENTRY(":status" , "204"), // 9
- STATIC_ENTRY(":status" , "206"), // 10
- STATIC_ENTRY(":status" , "304"), // 11
- STATIC_ENTRY(":status" , "400"), // 12
- STATIC_ENTRY(":status" , "404"), // 13
- STATIC_ENTRY(":status" , "500"), // 14
- STATIC_ENTRY("accept-charset" , ""), // 15
- STATIC_ENTRY("accept-encoding" , "gzip, deflate"), // 16
- STATIC_ENTRY("accept-language" , ""), // 17
- STATIC_ENTRY("accept-ranges" , ""), // 18
- STATIC_ENTRY("accept" , ""), // 19
- STATIC_ENTRY("access-control-allow-origin", ""), // 20
- STATIC_ENTRY("age" , ""), // 21
- STATIC_ENTRY("allow" , ""), // 22
- STATIC_ENTRY("authorization" , ""), // 23
- STATIC_ENTRY("cache-control" , ""), // 24
- STATIC_ENTRY("content-disposition" , ""), // 25
- STATIC_ENTRY("content-encoding" , ""), // 26
- STATIC_ENTRY("content-language" , ""), // 27
- STATIC_ENTRY("content-length" , ""), // 28
- STATIC_ENTRY("content-location" , ""), // 29
- STATIC_ENTRY("content-range" , ""), // 30
- STATIC_ENTRY("content-type" , ""), // 31
- STATIC_ENTRY("cookie" , ""), // 32
- STATIC_ENTRY("date" , ""), // 33
- STATIC_ENTRY("etag" , ""), // 34
- STATIC_ENTRY("expect" , ""), // 35
- STATIC_ENTRY("expires" , ""), // 36
- STATIC_ENTRY("from" , ""), // 37
- STATIC_ENTRY("host" , ""), // 38
- STATIC_ENTRY("if-match" , ""), // 39
- STATIC_ENTRY("if-modified-since" , ""), // 40
- STATIC_ENTRY("if-none-match" , ""), // 41
- STATIC_ENTRY("if-range" , ""), // 42
- STATIC_ENTRY("if-unmodified-since" , ""), // 43
- STATIC_ENTRY("last-modified" , ""), // 44
- STATIC_ENTRY("link" , ""), // 45
- STATIC_ENTRY("location" , ""), // 46
- STATIC_ENTRY("max-forwards" , ""), // 47
- STATIC_ENTRY("proxy-authenticate" , ""), // 48
- STATIC_ENTRY("proxy-authorization" , ""), // 49
- STATIC_ENTRY("range" , ""), // 50
- STATIC_ENTRY("referer" , ""), // 51
- STATIC_ENTRY("refresh" , ""), // 52
- STATIC_ENTRY("retry-after" , ""), // 53
- STATIC_ENTRY("server" , ""), // 54
- STATIC_ENTRY("set-cookie" , ""), // 55
- STATIC_ENTRY("strict-transport-security" , ""), // 56
- STATIC_ENTRY("transfer-encoding" , ""), // 57
- STATIC_ENTRY("user-agent" , ""), // 58
- STATIC_ENTRY("vary" , ""), // 59
- STATIC_ENTRY("via" , ""), // 60
- STATIC_ENTRY("www-authenticate" , ""), // 61
-};
-
-#undef STATIC_ENTRY
-
-} // namespace
-
bool HpackHeaderTable::EntryComparator::operator() (
const HpackEntry* lhs, const HpackEntry* rhs) const {
int result = lhs->name().compare(rhs->name());
@@ -107,8 +23,8 @@ bool HpackHeaderTable::EntryComparator::operator() (
result = lhs->value().compare(rhs->value());
if (result != 0)
return result < 0;
- const size_t lhs_index = table_->IndexOf(lhs);
- const size_t rhs_index = table_->IndexOf(rhs);
+ const size_t lhs_index = lhs->IsLookup() ? 0 : 1 + lhs->InsertionIndex();
+ const size_t rhs_index = rhs->IsLookup() ? 0 : 1 + rhs->InsertionIndex();
DCHECK(lhs == rhs || lhs_index != rhs_index)
<< "lhs: (" << lhs->name() << ", " << rhs->value() << ") rhs: ("
<< rhs->name() << ", " << rhs->value() << ")"
@@ -117,27 +33,16 @@ bool HpackHeaderTable::EntryComparator::operator() (
}
HpackHeaderTable::HpackHeaderTable()
- : index_(EntryComparator(this)),
+ : static_entries_(ObtainHpackStaticTable().GetStaticEntries()),
+ static_index_(ObtainHpackStaticTable().GetStaticIndex()),
settings_size_bound_(kDefaultHeaderTableSizeSetting),
size_(0),
max_size_(kDefaultHeaderTableSizeSetting),
- total_insertions_(0) {
- for (const StaticEntry* it = kStaticTable;
- it != kStaticTable + arraysize(kStaticTable); ++it) {
- static_entries_.push_back(
- HpackEntry(StringPiece(it->name, it->name_len),
- StringPiece(it->value, it->value_len),
- true, // is_static
- total_insertions_));
- CHECK(index_.insert(&static_entries_.back()).second);
-
- ++total_insertions_;
- }
-}
+ total_insertions_(static_entries_.size()) {}
HpackHeaderTable::~HpackHeaderTable() {}
-HpackEntry* HpackHeaderTable::GetByIndex(size_t index) {
+const HpackEntry* HpackHeaderTable::GetByIndex(size_t index) {
if (index == 0) {
return NULL;
}
@@ -152,21 +57,41 @@ HpackEntry* HpackHeaderTable::GetByIndex(size_t index) {
return NULL;
}
-HpackEntry* HpackHeaderTable::GetByName(StringPiece name) {
+const HpackEntry* HpackHeaderTable::GetByName(StringPiece name) {
HpackEntry query(name, "");
- OrderedEntrySet::const_iterator it = index_.lower_bound(&query);
- if (it != index_.end() && (*it)->name() == name) {
- return *it;
+ {
+ OrderedEntrySet::const_iterator it = static_index_.lower_bound(&query);
+ if (it != static_index_.end() && (*it)->name() == name) {
+ return *it;
+ }
+ }
+ {
+ OrderedEntrySet::const_iterator it = dynamic_index_.lower_bound(&query);
+ if (it != dynamic_index_.end() && (*it)->name() == name) {
+ return *it;
+ }
}
return NULL;
}
-HpackEntry* HpackHeaderTable::GetByNameAndValue(StringPiece name,
- StringPiece value) {
+const HpackEntry* HpackHeaderTable::GetByNameAndValue(StringPiece name,
+ StringPiece value) {
HpackEntry query(name, value);
- OrderedEntrySet::const_iterator it = index_.lower_bound(&query);
- if (it != index_.end() && (*it)->name() == name && (*it)->value() == value) {
- return *it;
+ {
+ OrderedEntrySet::const_iterator it = static_index_.lower_bound(&query);
+ if (it != static_index_.end() &&
+ (*it)->name() == name &&
+ (*it)->value() == value) {
+ return *it;
+ }
+ }
+ {
+ OrderedEntrySet::const_iterator it = dynamic_index_.lower_bound(&query);
+ if (it != dynamic_index_.end() &&
+ (*it)->name() == name &&
+ (*it)->value() == value) {
+ return *it;
+ }
}
return NULL;
}
@@ -234,12 +159,13 @@ void HpackHeaderTable::Evict(size_t count) {
HpackEntry* entry = &dynamic_entries_.back();
size_ -= entry->Size();
- CHECK_EQ(1u, index_.erase(entry));
+ CHECK_EQ(1u, dynamic_index_.erase(entry));
dynamic_entries_.pop_back();
}
}
-HpackEntry* HpackHeaderTable::TryAddEntry(StringPiece name, StringPiece value) {
+const HpackEntry* HpackHeaderTable::TryAddEntry(StringPiece name,
+ StringPiece value) {
Evict(EvictionCountForEntry(name, value));
size_t entry_size = HpackEntry::Size(name, value);
@@ -253,7 +179,7 @@ HpackEntry* HpackHeaderTable::TryAddEntry(StringPiece name, StringPiece value) {
value,
false, // is_static
total_insertions_));
- CHECK(index_.insert(&dynamic_entries_.front()).second);
+ CHECK(dynamic_index_.insert(&dynamic_entries_.front()).second);
size_ += entry_size;
++total_insertions_;
@@ -267,9 +193,14 @@ void HpackHeaderTable::DebugLogTableState() const {
it != dynamic_entries_.end(); ++it) {
DVLOG(2) << " " << it->GetDebugString();
}
- DVLOG(2) << "Full Index:";
- for (OrderedEntrySet::const_iterator it = index_.begin();
- it != index_.end(); ++it) {
+ DVLOG(2) << "Full Static Index:";
+ for (OrderedEntrySet::const_iterator it = static_index_.begin();
+ it != static_index_.end(); ++it) {
+ DVLOG(2) << " " << (*it)->GetDebugString();
+ }
+ DVLOG(2) << "Full Dynamic Index:";
+ for (OrderedEntrySet::const_iterator it = dynamic_index_.begin();
+ it != dynamic_index_.end(); ++it) {
DVLOG(2) << " " << (*it)->GetDebugString();
}
}
« no previous file with comments | « net/spdy/hpack_header_table.h ('k') | net/spdy/hpack_header_table_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698