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

Unified Diff: net/spdy/hpack_encoder.cc

Issue 243153003: HPACK optimal Huffman code instrumentation and UMA collection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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
Index: net/spdy/hpack_encoder.cc
diff --git a/net/spdy/hpack_encoder.cc b/net/spdy/hpack_encoder.cc
index 469042687718e25f7a23e689e1fb900688123818..d037fa837557199c1ee188da417042de8af65a4c 100644
--- a/net/spdy/hpack_encoder.cc
+++ b/net/spdy/hpack_encoder.cc
@@ -13,7 +13,10 @@ using base::StringPiece;
using std::string;
HpackEncoder::HpackEncoder()
- : max_string_literal_size_(kDefaultMaxStringLiteralSize) {}
+ : max_string_literal_size_(kDefaultMaxStringLiteralSize),
+ char_counts_(NULL),
+ total_char_counts_(NULL) {
+}
HpackEncoder::~HpackEncoder() {}
@@ -38,11 +41,20 @@ bool HpackEncoder::EncodeHeaderSet(const std::map<string, string>& header_set,
it->first, it->second)) {
return false;
}
+ UpdateCharacterCounts(it->first);
+ UpdateCharacterCounts(it->second);
}
output_stream.TakeString(output);
return true;
}
+void HpackEncoder::SetCharCountsStorage(std::vector<size_t>* char_counts,
+ size_t* total_char_counts) {
+ CHECK_LE(256u, char_counts->size());
+ char_counts_ = char_counts;
+ total_char_counts_ = total_char_counts;
+}
+
void HpackEncoder::CookieToCrumbs(StringPiece cookie,
std::vector<StringPiece>* out) {
out->clear();
@@ -63,4 +75,14 @@ void HpackEncoder::CookieToCrumbs(StringPiece cookie,
}
}
+void HpackEncoder::UpdateCharacterCounts(base::StringPiece str) {
+ if (char_counts_ == NULL || total_char_counts_ == NULL) {
+ return;
+ }
+ for (StringPiece::const_iterator it = str.begin(); it != str.end(); ++it) {
+ ++(*char_counts_)[static_cast<uint8>(*it)];
+ }
+ (*total_char_counts_) += str.size();
+}
+
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698