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

Unified Diff: net/spdy/hpack/hpack_entry.cc

Issue 1354773002: Avoid string construction overhead for lookup-only HpackEntry objects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit: return feels weird in a constructor. Created 5 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/hpack_entry.h ('k') | net/spdy/hpack/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/hpack_entry.cc
diff --git a/net/spdy/hpack/hpack_entry.cc b/net/spdy/hpack/hpack_entry.cc
index aad3bba394c52c28c48f413aff032d46a553e6fa..50bb718427975b08ac354623fcb2f1768c12e6e3 100644
--- a/net/spdy/hpack/hpack_entry.cc
+++ b/net/spdy/hpack/hpack_entry.cc
@@ -19,30 +19,61 @@ HpackEntry::HpackEntry(StringPiece name,
size_t insertion_index)
: name_(name.data(), name.size()),
value_(value.data(), value.size()),
+ name_ref_(name_),
+ value_ref_(value_),
insertion_index_(insertion_index),
type_(is_static ? STATIC : DYNAMIC) {}
HpackEntry::HpackEntry(StringPiece name, StringPiece value)
- : name_(name.data(), name.size()),
- value_(value.data(), value.size()),
- insertion_index_(0),
- type_(LOOKUP) {}
+ : name_ref_(name), value_ref_(value), insertion_index_(0), type_(LOOKUP) {}
HpackEntry::HpackEntry() : insertion_index_(0), type_(LOOKUP) {}
+HpackEntry::HpackEntry(const HpackEntry& other)
+ : insertion_index_(other.insertion_index_), type_(other.type_) {
+ if (type_ == LOOKUP) {
+ name_ref_ = other.name_ref_;
+ value_ref_ = other.value_ref_;
+ } else {
+ name_ = other.name_;
+ value_ = other.value_;
+ name_ref_.set(name_.data(), name_.size());
+ value_ref_.set(value_.data(), value_.size());
+ }
+}
+
+HpackEntry& HpackEntry::operator=(const HpackEntry& other) {
+ insertion_index_ = other.insertion_index_;
+ type_ = other.type_;
+ if (type_ == LOOKUP) {
+ name_ref_ = other.name_ref_;
+ value_ref_ = other.value_ref_;
+ return *this;
+ }
+ name_ = other.name_;
+ value_ = other.value_;
+ name_ref_.set(name_.data(), name_.size());
+ value_ref_.set(value_.data(), value_.size());
+ return *this;
+}
+
HpackEntry::~HpackEntry() {}
// static
size_t HpackEntry::Size(StringPiece name, StringPiece value) {
return name.size() + value.size() + kSizeOverhead;
}
+
size_t HpackEntry::Size() const {
return Size(name(), value());
}
std::string HpackEntry::GetDebugString() const {
- return "{ name: \"" + name_ + "\", value: \"" + value_ + "\", " +
- (IsStatic() ? "static" : "dynamic") + " }";
+ return "{ name: \"" + name_ref_.as_string() + "\", value: \"" +
+ value_ref_.as_string() + "\", index: " +
+ base::SizeTToString(insertion_index_) +
+ (IsStatic() ? " static" : (IsLookup() ? " lookup" : " dynamic")) +
+ " }";
}
} // namespace net
« no previous file with comments | « net/spdy/hpack/hpack_entry.h ('k') | net/spdy/hpack/hpack_header_table_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698