Move string in HpackDecoderDynamicTable::Insert().
PiperOrigin-RevId: 364626150
Change-Id: If362b84d33aa2afab9c9d1227ef09bc18b89ba3c
diff --git a/http2/hpack/decoder/hpack_decoder_state.cc b/http2/hpack/decoder/hpack_decoder_state.cc
index edc2167..3140a19 100644
--- a/http2/hpack/decoder/hpack_decoder_state.cc
+++ b/http2/hpack/decoder/hpack_decoder_state.cc
@@ -4,6 +4,8 @@
#include "http2/hpack/decoder/hpack_decoder_state.h"
+#include <utility>
+
#include "http2/http2_constants.h"
#include "http2/platform/api/http2_logging.h"
#include "http2/platform/api/http2_macros.h"
@@ -111,7 +113,7 @@
std::string value(ExtractString(value_buffer));
listener_->OnHeader(entry->name, value);
if (entry_type == HpackEntryType::kIndexedLiteralHeader) {
- decoder_tables_.Insert(entry->name, value);
+ decoder_tables_.Insert(entry->name, std::move(value));
}
} else {
ReportError(HpackDecodingError::kInvalidNameIndex, "");
@@ -136,7 +138,7 @@
std::string value(ExtractString(value_buffer));
listener_->OnHeader(name, value);
if (entry_type == HpackEntryType::kIndexedLiteralHeader) {
- decoder_tables_.Insert(name, value);
+ decoder_tables_.Insert(std::move(name), std::move(value));
}
}
diff --git a/http2/hpack/decoder/hpack_decoder_tables.cc b/http2/hpack/decoder/hpack_decoder_tables.cc
index e60dbd5..9f50ec7 100644
--- a/http2/hpack/decoder/hpack_decoder_tables.cc
+++ b/http2/hpack/decoder/hpack_decoder_tables.cc
@@ -4,8 +4,6 @@
#include "http2/hpack/decoder/hpack_decoder_tables.h"
-#include <utility>
-
#include "absl/strings/str_cat.h"
#include "http2/hpack/http2_hpack_constants.h"
#include "http2/platform/api/http2_logging.h"
@@ -82,12 +80,12 @@
// TODO(jamessynge): Check somewhere before here that names received from the
// peer are valid (e.g. are lower-case, no whitespace, etc.).
-void HpackDecoderDynamicTable::Insert(const std::string& name,
- const std::string& value) {
- HpackStringPair entry(name, value);
+void HpackDecoderDynamicTable::Insert(std::string name, std::string value) {
+ HpackStringPair entry(std::move(name), std::move(value));
size_t entry_size = entry.size();
HTTP2_DVLOG(2) << "InsertEntry of size=" << entry_size
- << "\n name: " << name << "\n value: " << value;
+ << "\n name: " << entry.name
+ << "\n value: " << entry.value;
if (entry_size > size_limit_) {
HTTP2_DVLOG(2) << "InsertEntry: entry larger than table, removing "
<< table_.size() << " entries, of total size "
diff --git a/http2/hpack/decoder/hpack_decoder_tables.h b/http2/hpack/decoder/hpack_decoder_tables.h
index c233472..45fce60 100644
--- a/http2/hpack/decoder/hpack_decoder_tables.h
+++ b/http2/hpack/decoder/hpack_decoder_tables.h
@@ -21,6 +21,7 @@
#include <cstdint>
#include <iosfwd>
#include <string>
+#include <utility>
#include <vector>
#include "http2/http2_constants.h"
@@ -88,7 +89,7 @@
// Insert entry if possible.
// If entry is too large to insert, then dynamic table will be empty.
- void Insert(const std::string& name, const std::string& value);
+ void Insert(std::string name, std::string value);
// If index is valid, returns a pointer to the entry, otherwise returns
// nullptr.
@@ -137,10 +138,8 @@
// Insert entry if possible.
// If entry is too large to insert, then dynamic table will be empty.
- // TODO(jamessynge): Add methods for moving the string(s) into the table,
- // or for otherwise avoiding unnecessary copies.
- void Insert(const std::string& name, const std::string& value) {
- dynamic_table_.Insert(name, value);
+ void Insert(std::string name, std::string value) {
+ dynamic_table_.Insert(std::move(name), std::move(value));
}
// If index is valid, returns a pointer to the entry, otherwise returns