Replace quiche::QuicheStringPiece with absl::string_view. PiperOrigin-RevId: 336805352 Change-Id: I90543ee2730573441efea777ef67729792796902
diff --git a/spdy/core/hpack/hpack_decoder_adapter.cc b/spdy/core/hpack/hpack_decoder_adapter.cc index cf9a0e7..fa54464 100644 --- a/spdy/core/hpack/hpack_decoder_adapter.cc +++ b/spdy/core/hpack/hpack_decoder_adapter.cc
@@ -185,7 +185,7 @@ } void HpackDecoderAdapter::ListenerAdapter::OnHeaderErrorDetected( - quiche::QuicheStringPiece error_message) { + absl::string_view error_message) { SPDY_VLOG(1) << error_message; }
diff --git a/spdy/core/hpack/hpack_decoder_adapter.h b/spdy/core/hpack/hpack_decoder_adapter.h index f521ee1..36f42b7 100644 --- a/spdy/core/hpack/hpack_decoder_adapter.h +++ b/spdy/core/hpack/hpack_decoder_adapter.h
@@ -13,13 +13,13 @@ #include <cstdint> #include <memory> +#include "absl/strings/string_view.h" #include "net/third_party/quiche/src/http2/hpack/decoder/hpack_decoder.h" #include "net/third_party/quiche/src/http2/hpack/decoder/hpack_decoder_listener.h" #include "net/third_party/quiche/src/http2/hpack/decoder/hpack_decoder_tables.h" #include "net/third_party/quiche/src/http2/hpack/hpack_string.h" #include "net/third_party/quiche/src/http2/hpack/http2_hpack_constants.h" #include "net/third_party/quiche/src/common/platform/api/quiche_export.h" -#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" #include "net/third_party/quiche/src/spdy/core/hpack/hpack_header_table.h" #include "net/third_party/quiche/src/spdy/core/spdy_header_block.h" #include "net/third_party/quiche/src/spdy/core/spdy_headers_handler_interface.h" @@ -113,8 +113,7 @@ void OnHeader(const http2::HpackString& name, const http2::HpackString& value) override; void OnHeaderListEnd() override; - void OnHeaderErrorDetected( - quiche::QuicheStringPiece error_message) override; + void OnHeaderErrorDetected(absl::string_view error_message) override; // Override the HpackDecoderTablesDebugListener methods: int64_t OnEntryInserted(const http2::HpackStringPair& entry,
diff --git a/spdy/core/hpack/hpack_decoder_adapter_test.cc b/spdy/core/hpack/hpack_decoder_adapter_test.cc index fb9bfbd..c1ed5d6 100644 --- a/spdy/core/hpack/hpack_decoder_adapter_test.cc +++ b/spdy/core/hpack/hpack_decoder_adapter_test.cc
@@ -65,8 +65,8 @@ explicit HpackDecoderAdapterPeer(HpackDecoderAdapter* decoder) : decoder_(decoder) {} - void HandleHeaderRepresentation(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value) { + void HandleHeaderRepresentation(absl::string_view name, + absl::string_view value) { decoder_->listener_adapter_.OnHeader(HpackString(name), HpackString(value)); } @@ -133,7 +133,7 @@ } } - bool HandleControlFrameHeadersData(quiche::QuicheStringPiece str) { + bool HandleControlFrameHeadersData(absl::string_view str) { SPDY_VLOG(3) << "HandleControlFrameHeadersData:\n" << SpdyHexDump(str); bytes_passed_in_ += str.size(); return decoder_.HandleControlFrameHeadersData(str.data(), str.size()); @@ -147,7 +147,7 @@ return rc; } - bool DecodeHeaderBlock(quiche::QuicheStringPiece str, + bool DecodeHeaderBlock(absl::string_view str, bool check_decoded_size = true) { // Don't call this again if HandleControlFrameHeadersData failed previously. EXPECT_FALSE(decode_has_failed_); @@ -225,8 +225,7 @@ return size; } - const SpdyHeaderBlock& DecodeBlockExpectingSuccess( - quiche::QuicheStringPiece str) { + const SpdyHeaderBlock& DecodeBlockExpectingSuccess(absl::string_view str) { EXPECT_TRUE(DecodeHeaderBlock(str)); return decoded_block(); } @@ -434,11 +433,10 @@ decoded_block(), ElementsAre( Pair("cookie", " part 1; part 2 ; part3; fin!"), - Pair("passed-through", quiche::QuicheStringPiece("foo\0baz", 7)), - Pair("joined", - quiche::QuicheStringPiece("joined\0value 1\0value 2", 22)), + Pair("passed-through", absl::string_view("foo\0baz", 7)), + Pair("joined", absl::string_view("joined\0value 1\0value 2", 22)), Pair("empty", ""), - Pair("empty-joined", quiche::QuicheStringPiece("\0foo\0\0", 6)))); + Pair("empty-joined", absl::string_view("\0foo\0\0", 6)))); } // Decoding indexed static table field should work. @@ -503,7 +501,7 @@ output_stream.AppendUint32(126); output_stream.TakeString(&input); - EXPECT_TRUE(DecodeHeaderBlock(quiche::QuicheStringPiece(input))); + EXPECT_TRUE(DecodeHeaderBlock(absl::string_view(input))); EXPECT_EQ(126u, decoder_peer_.header_table_size_limit()); } { @@ -513,7 +511,7 @@ output_stream.AppendUint32(kDefaultHeaderTableSizeSetting); output_stream.TakeString(&input); - EXPECT_TRUE(DecodeHeaderBlock(quiche::QuicheStringPiece(input))); + EXPECT_TRUE(DecodeHeaderBlock(absl::string_view(input))); EXPECT_EQ(kDefaultHeaderTableSizeSetting, decoder_peer_.header_table_size_limit()); } @@ -524,7 +522,7 @@ output_stream.AppendUint32(kDefaultHeaderTableSizeSetting + 1); output_stream.TakeString(&input); - EXPECT_FALSE(DecodeHeaderBlock(quiche::QuicheStringPiece(input))); + EXPECT_FALSE(DecodeHeaderBlock(absl::string_view(input))); EXPECT_EQ(kDefaultHeaderTableSizeSetting, decoder_peer_.header_table_size_limit()); } @@ -542,7 +540,7 @@ output_stream.AppendUint32(122); output_stream.TakeString(&input); - EXPECT_TRUE(DecodeHeaderBlock(quiche::QuicheStringPiece(input))); + EXPECT_TRUE(DecodeHeaderBlock(absl::string_view(input))); EXPECT_EQ(122u, decoder_peer_.header_table_size_limit()); } } @@ -562,7 +560,7 @@ output_stream.TakeString(&input); - EXPECT_FALSE(DecodeHeaderBlock(quiche::QuicheStringPiece(input))); + EXPECT_FALSE(DecodeHeaderBlock(absl::string_view(input))); EXPECT_EQ(10u, decoder_peer_.header_table_size_limit()); } } @@ -581,7 +579,7 @@ output_stream.TakeString(&input); - EXPECT_FALSE(DecodeHeaderBlock(quiche::QuicheStringPiece(input))); + EXPECT_FALSE(DecodeHeaderBlock(absl::string_view(input))); EXPECT_EQ(kDefaultHeaderTableSizeSetting, decoder_peer_.header_table_size_limit()); } @@ -604,7 +602,7 @@ output_stream.TakeString(&input); - EXPECT_FALSE(DecodeHeaderBlock(quiche::QuicheStringPiece(input))); + EXPECT_FALSE(DecodeHeaderBlock(absl::string_view(input))); EXPECT_EQ(60u, decoder_peer_.header_table_size_limit()); } } @@ -616,7 +614,7 @@ // name. const char input[] = "\x04\x0c/sample/path\x00\x06:path2\x0e/sample/path/2"; const SpdyHeaderBlock& header_set = DecodeBlockExpectingSuccess( - quiche::QuicheStringPiece(input, QUICHE_ARRAYSIZE(input) - 1)); + absl::string_view(input, QUICHE_ARRAYSIZE(input) - 1)); SpdyHeaderBlock expected_header_set; expected_header_set[":path"] = "/sample/path"; @@ -629,7 +627,7 @@ TEST_P(HpackDecoderAdapterTest, LiteralHeaderIncrementalIndexing) { const char input[] = "\x44\x0c/sample/path\x40\x06:path2\x0e/sample/path/2"; const SpdyHeaderBlock& header_set = DecodeBlockExpectingSuccess( - quiche::QuicheStringPiece(input, QUICHE_ARRAYSIZE(input) - 1)); + absl::string_view(input, QUICHE_ARRAYSIZE(input) - 1)); SpdyHeaderBlock expected_header_set; expected_header_set[":path"] = "/sample/path"; @@ -642,23 +640,23 @@ EXPECT_TRUE(EncodeAndDecodeDynamicTableSizeUpdates(0, 0)); // Name is the last static index. Works. - EXPECT_TRUE(DecodeHeaderBlock(quiche::QuicheStringPiece("\x7d\x03ooo"))); + EXPECT_TRUE(DecodeHeaderBlock(absl::string_view("\x7d\x03ooo"))); // Name is one beyond the last static index. Fails. - EXPECT_FALSE(DecodeHeaderBlock(quiche::QuicheStringPiece("\x7e\x03ooo"))); + EXPECT_FALSE(DecodeHeaderBlock(absl::string_view("\x7e\x03ooo"))); } TEST_P(HpackDecoderAdapterTest, LiteralHeaderNoIndexingInvalidNameIndex) { // Name is the last static index. Works. - EXPECT_TRUE(DecodeHeaderBlock(quiche::QuicheStringPiece("\x0f\x2e\x03ooo"))); + EXPECT_TRUE(DecodeHeaderBlock(absl::string_view("\x0f\x2e\x03ooo"))); // Name is one beyond the last static index. Fails. - EXPECT_FALSE(DecodeHeaderBlock(quiche::QuicheStringPiece("\x0f\x2f\x03ooo"))); + EXPECT_FALSE(DecodeHeaderBlock(absl::string_view("\x0f\x2f\x03ooo"))); } TEST_P(HpackDecoderAdapterTest, LiteralHeaderNeverIndexedInvalidNameIndex) { // Name is the last static index. Works. - EXPECT_TRUE(DecodeHeaderBlock(quiche::QuicheStringPiece("\x1f\x2e\x03ooo"))); + EXPECT_TRUE(DecodeHeaderBlock(absl::string_view("\x1f\x2e\x03ooo"))); // Name is one beyond the last static index. Fails. - EXPECT_FALSE(DecodeHeaderBlock(quiche::QuicheStringPiece("\x1f\x2f\x03ooo"))); + EXPECT_FALSE(DecodeHeaderBlock(absl::string_view("\x1f\x2f\x03ooo"))); } TEST_P(HpackDecoderAdapterTest, TruncatedIndex) { @@ -1055,10 +1053,10 @@ hbb.AppendDynamicTableSizeUpdate(0); hbb.AppendDynamicTableSizeUpdate(63); - const quiche::QuicheStringPiece name("some-name"); - const quiche::QuicheStringPiece value1("some-value"); - const quiche::QuicheStringPiece value2("another-value"); - const quiche::QuicheStringPiece value3("yet-another-value"); + const absl::string_view name("some-name"); + const absl::string_view value1("some-value"); + const absl::string_view value2("another-value"); + const absl::string_view value3("yet-another-value"); // Add an entry that will become the first in the dynamic table, entry 62. hbb.AppendLiteralNameAndValue(HpackEntryType::kIndexedLiteralHeader, false,
diff --git a/spdy/core/hpack/hpack_encoder.cc b/spdy/core/hpack/hpack_encoder.cc index 566f4ee..6ad6a5f 100644 --- a/spdy/core/hpack/hpack_encoder.cc +++ b/spdy/core/hpack/hpack_encoder.cc
@@ -58,12 +58,10 @@ namespace { // The default header listener. -void NoOpListener(quiche::QuicheStringPiece /*name*/, - quiche::QuicheStringPiece /*value*/) {} +void NoOpListener(absl::string_view /*name*/, absl::string_view /*value*/) {} // The default HPACK indexing policy. -bool DefaultPolicy(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece /* value */) { +bool DefaultPolicy(absl::string_view name, absl::string_view /* value */) { if (name.empty()) { return false; } @@ -200,7 +198,7 @@ EmitString(representation.second); } -void HpackEncoder::EmitString(quiche::QuicheStringPiece str) { +void HpackEncoder::EmitString(absl::string_view str) { size_t encoded_size = enable_compression_ ? (use_fast_huffman_encoder_ ? http2::HuffmanSize(str) @@ -249,21 +247,19 @@ // See Section 8.1.2.5. "Compressing the Cookie Header Field" in the HTTP/2 // specification at https://tools.ietf.org/html/draft-ietf-httpbis-http2-14. // Cookie values are split into individually-encoded HPACK representations. - quiche::QuicheStringPiece cookie_value = cookie.second; + absl::string_view cookie_value = cookie.second; // Consume leading and trailing whitespace if present. - quiche::QuicheStringPiece::size_type first = - cookie_value.find_first_not_of(" \t"); - quiche::QuicheStringPiece::size_type last = - cookie_value.find_last_not_of(" \t"); - if (first == quiche::QuicheStringPiece::npos) { - cookie_value = quiche::QuicheStringPiece(); + absl::string_view::size_type first = cookie_value.find_first_not_of(" \t"); + absl::string_view::size_type last = cookie_value.find_last_not_of(" \t"); + if (first == absl::string_view::npos) { + cookie_value = absl::string_view(); } else { cookie_value = cookie_value.substr(first, (last - first) + 1); } for (size_t pos = 0;;) { size_t end = cookie_value.find(";", pos); - if (end == quiche::QuicheStringPiece::npos) { + if (end == absl::string_view::npos) { out->push_back(std::make_pair(cookie.first, cookie_value.substr(pos))); break; } @@ -283,12 +279,12 @@ Representations* out) { size_t pos = 0; size_t end = 0; - while (end != quiche::QuicheStringPiece::npos) { + while (end != absl::string_view::npos) { end = header_field.second.find('\0', pos); out->push_back(std::make_pair( header_field.first, header_field.second.substr( - pos, end == quiche::QuicheStringPiece::npos ? end : end - pos))); + pos, end == absl::string_view::npos ? end : end - pos))); pos = end + 1; } }
diff --git a/spdy/core/hpack/hpack_encoder.h b/spdy/core/hpack/hpack_encoder.h index 3b3e0d1..f9cc0d1 100644 --- a/spdy/core/hpack/hpack_encoder.h +++ b/spdy/core/hpack/hpack_encoder.h
@@ -14,8 +14,8 @@ #include <utility> #include <vector> +#include "absl/strings/string_view.h" #include "net/third_party/quiche/src/common/platform/api/quiche_export.h" -#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" #include "net/third_party/quiche/src/spdy/core/hpack/hpack_header_table.h" #include "net/third_party/quiche/src/spdy/core/hpack/hpack_output_stream.h" #include "net/third_party/quiche/src/spdy/core/spdy_protocol.h" @@ -33,19 +33,18 @@ class QUICHE_EXPORT_PRIVATE HpackEncoder { public: - using Representation = - std::pair<quiche::QuicheStringPiece, quiche::QuicheStringPiece>; + using Representation = std::pair<absl::string_view, absl::string_view>; using Representations = std::vector<Representation>; // Callers may provide a HeaderListener to be informed of header name-value // pairs processed by this encoder. using HeaderListener = - std::function<void(quiche::QuicheStringPiece, quiche::QuicheStringPiece)>; + std::function<void(absl::string_view, absl::string_view)>; // An indexing policy should return true if the provided header name-value // pair should be inserted into the HPACK dynamic table. using IndexingPolicy = - std::function<bool(quiche::QuicheStringPiece, quiche::QuicheStringPiece)>; + std::function<bool(absl::string_view, absl::string_view)>; HpackEncoder(); HpackEncoder(const HpackEncoder&) = delete; @@ -125,7 +124,7 @@ void EmitLiteral(const Representation& representation); // Emits a Huffman or identity string (whichever is smaller). - void EmitString(quiche::QuicheStringPiece str); + void EmitString(absl::string_view str); // Emits the current dynamic table size if the table size was recently // updated and we have not yet emitted it (Section 6.3).
diff --git a/spdy/core/hpack/hpack_encoder_test.cc b/spdy/core/hpack/hpack_encoder_test.cc index 62c7887..52693db 100644 --- a/spdy/core/hpack/hpack_encoder_test.cc +++ b/spdy/core/hpack/hpack_encoder_test.cc
@@ -40,12 +40,12 @@ bool compression_enabled() const { return encoder_->enable_compression_; } HpackHeaderTable* table() { return &encoder_->header_table_; } HpackHeaderTablePeer table_peer() { return HpackHeaderTablePeer(table()); } - void EmitString(quiche::QuicheStringPiece str) { encoder_->EmitString(str); } + void EmitString(absl::string_view str) { encoder_->EmitString(str); } void TakeString(std::string* out) { encoder_->output_stream_.TakeString(out); } - static void CookieToCrumbs(quiche::QuicheStringPiece cookie, - std::vector<quiche::QuicheStringPiece>* out) { + static void CookieToCrumbs(absl::string_view cookie, + std::vector<absl::string_view>* out) { Representations tmp; HpackEncoder::CookieToCrumbs(std::make_pair("", cookie), &tmp); @@ -54,9 +54,8 @@ out->push_back(tmp[i].second); } } - static void DecomposeRepresentation( - quiche::QuicheStringPiece value, - std::vector<quiche::QuicheStringPiece>* out) { + static void DecomposeRepresentation(absl::string_view value, + std::vector<absl::string_view>* out) { Representations tmp; HpackEncoder::DecomposeRepresentation(std::make_pair("foobar", value), &tmp); @@ -150,12 +149,11 @@ peer_.table()->SetMaxSize(peer_.table()->size()); } - void SaveHeaders(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value) { - quiche::QuicheStringPiece n( - headers_storage_.Memdup(name.data(), name.size()), name.size()); - quiche::QuicheStringPiece v( - headers_storage_.Memdup(value.data(), value.size()), value.size()); + void SaveHeaders(absl::string_view name, absl::string_view value) { + absl::string_view n(headers_storage_.Memdup(name.data(), name.size()), + name.size()); + absl::string_view v(headers_storage_.Memdup(value.data(), value.size()), + value.size()); headers_observed_.push_back(std::make_pair(n, v)); } @@ -164,32 +162,31 @@ expected_.AppendUint32(index); } void ExpectIndexedLiteral(const HpackEntry* key_entry, - quiche::QuicheStringPiece value) { + absl::string_view value) { expected_.AppendPrefix(kLiteralIncrementalIndexOpcode); expected_.AppendUint32(IndexOf(key_entry)); ExpectString(&expected_, value); } - void ExpectIndexedLiteral(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value) { + void ExpectIndexedLiteral(absl::string_view name, absl::string_view value) { expected_.AppendPrefix(kLiteralIncrementalIndexOpcode); expected_.AppendUint32(0); ExpectString(&expected_, name); ExpectString(&expected_, value); } - void ExpectNonIndexedLiteral(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value) { + void ExpectNonIndexedLiteral(absl::string_view name, + absl::string_view value) { expected_.AppendPrefix(kLiteralNoIndexOpcode); expected_.AppendUint32(0); ExpectString(&expected_, name); ExpectString(&expected_, value); } void ExpectNonIndexedLiteralWithNameIndex(const HpackEntry* key_entry, - quiche::QuicheStringPiece value) { + absl::string_view value) { expected_.AppendPrefix(kLiteralNoIndexOpcode); expected_.AppendUint32(IndexOf(key_entry)); ExpectString(&expected_, value); } - void ExpectString(HpackOutputStream* stream, quiche::QuicheStringPiece str) { + void ExpectString(HpackOutputStream* stream, absl::string_view str) { const HpackHuffmanTable& huffman_table = ObtainHpackHuffmanTable(); size_t encoded_size = peer_.compression_enabled() @@ -261,7 +258,7 @@ const HpackEntry* cookie_c_; SpdySimpleArena headers_storage_; - std::vector<std::pair<quiche::QuicheStringPiece, quiche::QuicheStringPiece>> + std::vector<std::pair<absl::string_view, absl::string_view>> headers_observed_; HpackOutputStream expected_; @@ -278,16 +275,15 @@ TEST_P(HpackEncoderTestWithDefaultStrategy, EncodeRepresentations) { encoder_.SetHeaderListener( - [this](quiche::QuicheStringPiece name, quiche::QuicheStringPiece value) { + [this](absl::string_view name, absl::string_view value) { this->SaveHeaders(name, value); }); - const std::vector< - std::pair<quiche::QuicheStringPiece, quiche::QuicheStringPiece>> + const std::vector<std::pair<absl::string_view, absl::string_view>> header_list = {{"cookie", "val1; val2;val3"}, {":path", "/home"}, {"accept", "text/html, text/plain,application/xml"}, {"cookie", "val4"}, - {"withnul", quiche::QuicheStringPiece("one\0two", 7)}}; + {"withnul", absl::string_view("one\0two", 7)}}; ExpectNonIndexedLiteralWithNameIndex(peer_.table()->GetByName(":path"), "/home"); ExpectIndexedLiteral(peer_.table()->GetByName("cookie"), "val1"); @@ -296,7 +292,7 @@ ExpectIndexedLiteral(peer_.table()->GetByName("accept"), "text/html, text/plain,application/xml"); ExpectIndexedLiteral(peer_.table()->GetByName("cookie"), "val4"); - ExpectIndexedLiteral("withnul", quiche::QuicheStringPiece("one\0two", 7)); + ExpectIndexedLiteral("withnul", absl::string_view("one\0two", 7)); CompareWithExpectedEncoding(header_list); EXPECT_THAT( @@ -305,7 +301,7 @@ Pair("cookie", "val2"), Pair("cookie", "val3"), Pair("accept", "text/html, text/plain,application/xml"), Pair("cookie", "val4"), - Pair("withnul", quiche::QuicheStringPiece("one\0two", 7)))); + Pair("withnul", absl::string_view("one\0two", 7)))); } INSTANTIATE_TEST_SUITE_P(HpackEncoderTests, @@ -317,7 +313,7 @@ TEST_P(HpackEncoderTest, SingleDynamicIndex) { encoder_.SetHeaderListener( - [this](quiche::QuicheStringPiece name, quiche::QuicheStringPiece value) { + [this](absl::string_view name, absl::string_view value) { this->SaveHeaders(name, value); }); @@ -438,7 +434,7 @@ TEST_P(HpackEncoderTest, EncodingWithoutCompression) { encoder_.SetHeaderListener( - [this](quiche::QuicheStringPiece name, quiche::QuicheStringPiece value) { + [this](absl::string_view name, absl::string_view value) { this->SaveHeaders(name, value); }); encoder_.DisableCompression(); @@ -466,11 +462,10 @@ if (strategy_ == kRepresentations) { EXPECT_THAT( headers_observed_, - ElementsAre( - Pair(":path", "/index.html"), Pair("cookie", "foo=bar"), - Pair("cookie", "baz=bing"), - Pair("hello", quiche::QuicheStringPiece("goodbye\0aloha", 13)), - Pair("multivalue", "value1, value2"))); + ElementsAre(Pair(":path", "/index.html"), Pair("cookie", "foo=bar"), + Pair("cookie", "baz=bing"), + Pair("hello", absl::string_view("goodbye\0aloha", 13)), + Pair("multivalue", "value1, value2"))); } else { EXPECT_THAT( headers_observed_, @@ -483,7 +478,7 @@ TEST_P(HpackEncoderTest, MultipleEncodingPasses) { encoder_.SetHeaderListener( - [this](quiche::QuicheStringPiece name, quiche::QuicheStringPiece value) { + [this](absl::string_view name, absl::string_view value) { this->SaveHeaders(name, value); }); @@ -580,7 +575,7 @@ TEST_P(HpackEncoderTest, CookieToCrumbs) { test::HpackEncoderPeer peer(nullptr); - std::vector<quiche::QuicheStringPiece> out; + std::vector<absl::string_view> out; // Leading and trailing whitespace is consumed. A space after ';' is consumed. // All other spaces remain. ';' at beginning and end of string produce empty @@ -614,7 +609,7 @@ TEST_P(HpackEncoderTest, DecomposeRepresentation) { test::HpackEncoderPeer peer(nullptr); - std::vector<quiche::QuicheStringPiece> out; + std::vector<absl::string_view> out; peer.DecomposeRepresentation("", &out); EXPECT_THAT(out, ElementsAre("")); @@ -622,19 +617,16 @@ peer.DecomposeRepresentation("foobar", &out); EXPECT_THAT(out, ElementsAre("foobar")); - peer.DecomposeRepresentation(quiche::QuicheStringPiece("foo\0bar", 7), &out); + peer.DecomposeRepresentation(absl::string_view("foo\0bar", 7), &out); EXPECT_THAT(out, ElementsAre("foo", "bar")); - peer.DecomposeRepresentation(quiche::QuicheStringPiece("\0foo\0bar", 8), - &out); + peer.DecomposeRepresentation(absl::string_view("\0foo\0bar", 8), &out); EXPECT_THAT(out, ElementsAre("", "foo", "bar")); - peer.DecomposeRepresentation(quiche::QuicheStringPiece("foo\0bar\0", 8), - &out); + peer.DecomposeRepresentation(absl::string_view("foo\0bar\0", 8), &out); EXPECT_THAT(out, ElementsAre("foo", "bar", "")); - peer.DecomposeRepresentation(quiche::QuicheStringPiece("\0foo\0bar\0", 9), - &out); + peer.DecomposeRepresentation(absl::string_view("\0foo\0bar\0", 9), &out); EXPECT_THAT(out, ElementsAre("", "foo", "bar", "")); }
diff --git a/spdy/core/hpack/hpack_entry.cc b/spdy/core/hpack/hpack_entry.cc index 586f321..7f251e6 100644 --- a/spdy/core/hpack/hpack_entry.cc +++ b/spdy/core/hpack/hpack_entry.cc
@@ -12,8 +12,8 @@ const size_t HpackEntry::kSizeOverhead = 32; -HpackEntry::HpackEntry(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value, +HpackEntry::HpackEntry(absl::string_view name, + absl::string_view value, bool is_static, size_t insertion_index) : name_(name.data(), name.size()), @@ -24,8 +24,7 @@ type_(is_static ? STATIC : DYNAMIC), time_added_(0) {} -HpackEntry::HpackEntry(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value) +HpackEntry::HpackEntry(absl::string_view name, absl::string_view value) : name_ref_(name), value_ref_(value), insertion_index_(0), @@ -44,8 +43,8 @@ } else { name_ = other.name_; value_ = other.value_; - name_ref_ = quiche::QuicheStringPiece(name_.data(), name_.size()); - value_ref_ = quiche::QuicheStringPiece(value_.data(), value_.size()); + name_ref_ = absl::string_view(name_.data(), name_.size()); + value_ref_ = absl::string_view(value_.data(), value_.size()); } } @@ -61,16 +60,15 @@ } name_ = other.name_; value_ = other.value_; - name_ref_ = quiche::QuicheStringPiece(name_.data(), name_.size()); - value_ref_ = quiche::QuicheStringPiece(value_.data(), value_.size()); + name_ref_ = absl::string_view(name_.data(), name_.size()); + value_ref_ = absl::string_view(value_.data(), value_.size()); return *this; } HpackEntry::~HpackEntry() = default; // static -size_t HpackEntry::Size(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value) { +size_t HpackEntry::Size(absl::string_view name, absl::string_view value) { return name.size() + value.size() + kSizeOverhead; } size_t HpackEntry::Size() const {
diff --git a/spdy/core/hpack/hpack_entry.h b/spdy/core/hpack/hpack_entry.h index 750c7e6..e9c4efc 100644 --- a/spdy/core/hpack/hpack_entry.h +++ b/spdy/core/hpack/hpack_entry.h
@@ -9,8 +9,8 @@ #include <cstdint> #include <string> +#include "absl/strings/string_view.h" #include "net/third_party/quiche/src/common/platform/api/quiche_export.h" -#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" // All section references below are to // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 @@ -34,15 +34,15 @@ // The combination of |is_static| and |insertion_index| allows an // HpackEntryTable to determine the index of an HpackEntry in O(1) time. // Copies |name| and |value|. - HpackEntry(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value, + HpackEntry(absl::string_view name, + absl::string_view value, bool is_static, size_t insertion_index); // Create a 'lookup' entry (only) suitable for querying a HpackEntrySet. The // instance InsertionIndex() always returns 0 and IsLookup() returns true. // The memory backing |name| and |value| must outlive this object. - HpackEntry(quiche::QuicheStringPiece name, quiche::QuicheStringPiece value); + HpackEntry(absl::string_view name, absl::string_view value); HpackEntry(const HpackEntry& other); HpackEntry& operator=(const HpackEntry& other); @@ -53,8 +53,8 @@ ~HpackEntry(); - quiche::QuicheStringPiece name() const { return name_ref_; } - quiche::QuicheStringPiece value() const { return value_ref_; } + absl::string_view name() const { return name_ref_; } + absl::string_view value() const { return value_ref_; } // Returns whether this entry is a member of the static (as opposed to // dynamic) table. @@ -67,8 +67,7 @@ size_t InsertionIndex() const { return insertion_index_; } // Returns the size of an entry as defined in 5.1. - static size_t Size(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value); + static size_t Size(absl::string_view name, absl::string_view value); size_t Size() const; std::string GetDebugString() const; @@ -92,8 +91,8 @@ // These members are always valid. For DYNAMIC and STATIC entries, they // always point to |name_| and |value_|. - quiche::QuicheStringPiece name_ref_; - quiche::QuicheStringPiece value_ref_; + absl::string_view name_ref_; + absl::string_view value_ref_; // The entry's index in the total set of entries ever inserted into the header // table.
diff --git a/spdy/core/hpack/hpack_header_table.cc b/spdy/core/hpack/hpack_header_table.cc index 67a0a5f..1ecfd79 100644 --- a/spdy/core/hpack/hpack_header_table.cc +++ b/spdy/core/hpack/hpack_header_table.cc
@@ -60,7 +60,7 @@ return nullptr; } -const HpackEntry* HpackHeaderTable::GetByName(quiche::QuicheStringPiece name) { +const HpackEntry* HpackHeaderTable::GetByName(absl::string_view name) { { auto it = static_name_index_.find(name); if (it != static_name_index_.end()) { @@ -80,9 +80,8 @@ return nullptr; } -const HpackEntry* HpackHeaderTable::GetByNameAndValue( - quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value) { +const HpackEntry* HpackHeaderTable::GetByNameAndValue(absl::string_view name, + absl::string_view value) { HpackEntry query(name, value); { auto it = static_index_.find(&query); @@ -128,8 +127,8 @@ SetMaxSize(settings_size_bound_); } -void HpackHeaderTable::EvictionSet(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value, +void HpackHeaderTable::EvictionSet(absl::string_view name, + absl::string_view value, EntryTable::iterator* begin_out, EntryTable::iterator* end_out) { size_t eviction_count = EvictionCountForEntry(name, value); @@ -137,9 +136,8 @@ *end_out = dynamic_entries_.end(); } -size_t HpackHeaderTable::EvictionCountForEntry( - quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value) const { +size_t HpackHeaderTable::EvictionCountForEntry(absl::string_view name, + absl::string_view value) const { size_t available_size = max_size_ - size_; size_t entry_size = HpackEntry::Size(name, value); @@ -185,9 +183,8 @@ } } -const HpackEntry* HpackHeaderTable::TryAddEntry( - quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value) { +const HpackEntry* HpackHeaderTable::TryAddEntry(absl::string_view name, + absl::string_view value) { Evict(EvictionCountForEntry(name, value)); size_t entry_size = HpackEntry::Size(name, value);
diff --git a/spdy/core/hpack/hpack_header_table.h b/spdy/core/hpack/hpack_header_table.h index 88ef6d7..7f558bd 100644 --- a/spdy/core/hpack/hpack_header_table.h +++ b/spdy/core/hpack/hpack_header_table.h
@@ -10,6 +10,7 @@ #include <deque> #include <memory> +#include "absl/strings/string_view.h" #include "net/third_party/quiche/src/common/platform/api/quiche_export.h" #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" #include "net/third_party/quiche/src/spdy/core/hpack/hpack_entry.h" @@ -67,7 +68,7 @@ bool operator()(const HpackEntry* lhs, const HpackEntry* rhs) const; }; using UnorderedEntrySet = SpdyHashSet<HpackEntry*, EntryHasher, EntriesEq>; - using NameToEntryMap = SpdyHashMap<quiche::QuicheStringPiece, + using NameToEntryMap = SpdyHashMap<absl::string_view, const HpackEntry*, quiche::QuicheStringPieceHash>; @@ -89,11 +90,11 @@ const HpackEntry* GetByIndex(size_t index); // Returns the lowest-value entry having |name|, or NULL. - const HpackEntry* GetByName(quiche::QuicheStringPiece name); + const HpackEntry* GetByName(absl::string_view name); // Returns the lowest-index matching entry, or NULL. - const HpackEntry* GetByNameAndValue(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value); + const HpackEntry* GetByNameAndValue(absl::string_view name, + absl::string_view value); // Returns the index of an entry within this header table. size_t IndexOf(const HpackEntry* entry) const; @@ -109,8 +110,8 @@ // Determine the set of entries which would be evicted by the insertion // of |name| & |value| into the table, as per section 4.4. No eviction // actually occurs. The set is returned via range [begin_out, end_out). - void EvictionSet(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value, + void EvictionSet(absl::string_view name, + absl::string_view value, EntryTable::iterator* begin_out, EntryTable::iterator* end_out); @@ -118,8 +119,8 @@ // and |value| must not be owned by an entry which could be evicted. The // added HpackEntry is returned, or NULL is returned if all entries were // evicted and the empty table is of insufficent size for the representation. - const HpackEntry* TryAddEntry(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value); + const HpackEntry* TryAddEntry(absl::string_view name, + absl::string_view value); void DebugLogTableState() const SPDY_UNUSED; @@ -132,8 +133,8 @@ private: // Returns number of evictions required to enter |name| & |value|. - size_t EvictionCountForEntry(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value) const; + size_t EvictionCountForEntry(absl::string_view name, + absl::string_view value) const; // Returns number of evictions required to reclaim |reclaim_size| table size. size_t EvictionCountToReclaim(size_t reclaim_size) const;
diff --git a/spdy/core/hpack/hpack_header_table_test.cc b/spdy/core/hpack/hpack_header_table_test.cc index cc5674f..0b6799e 100644 --- a/spdy/core/hpack/hpack_header_table_test.cc +++ b/spdy/core/hpack/hpack_header_table_test.cc
@@ -33,8 +33,8 @@ size_t index_size() { return table_->static_index_.size() + table_->dynamic_index_.size(); } - std::vector<HpackEntry*> EvictionSet(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value) { + std::vector<HpackEntry*> EvictionSet(absl::string_view name, + absl::string_view value) { HpackHeaderTable::EntryTable::iterator begin, end; table_->EvictionSet(name, value, &begin, &end); std::vector<HpackEntry*> result; @@ -45,8 +45,8 @@ } size_t total_insertions() { return table_->total_insertions_; } size_t dynamic_entries_count() { return table_->dynamic_entries_.size(); } - size_t EvictionCountForEntry(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value) { + size_t EvictionCountForEntry(absl::string_view name, + absl::string_view value) { return table_->EvictionCountForEntry(name, value); } size_t EvictionCountToReclaim(size_t reclaim_size) { @@ -54,8 +54,7 @@ } void Evict(size_t count) { return table_->Evict(count); } - void AddDynamicEntry(quiche::QuicheStringPiece name, - quiche::QuicheStringPiece value) { + void AddDynamicEntry(absl::string_view name, absl::string_view value) { table_->dynamic_entries_.push_back( HpackEntry(name, value, false, table_->total_insertions_++)); }
diff --git a/spdy/core/hpack/hpack_huffman_table.cc b/spdy/core/hpack/hpack_huffman_table.cc index eb799d0..aac6d1b 100644 --- a/spdy/core/hpack/hpack_huffman_table.cc +++ b/spdy/core/hpack/hpack_huffman_table.cc
@@ -96,7 +96,7 @@ return !code_by_id_.empty(); } -void HpackHuffmanTable::EncodeString(quiche::QuicheStringPiece in, +void HpackHuffmanTable::EncodeString(absl::string_view in, HpackOutputStream* out) const { size_t bit_remnant = 0; for (size_t i = 0; i != in.size(); i++) { @@ -129,7 +129,7 @@ } } -size_t HpackHuffmanTable::EncodedSize(quiche::QuicheStringPiece in) const { +size_t HpackHuffmanTable::EncodedSize(absl::string_view in) const { size_t bit_count = 0; for (size_t i = 0; i != in.size(); i++) { uint16_t symbol_id = static_cast<uint8_t>(in[i]);
diff --git a/spdy/core/hpack/hpack_huffman_table.h b/spdy/core/hpack/hpack_huffman_table.h index b7c2649..81af770 100644 --- a/spdy/core/hpack/hpack_huffman_table.h +++ b/spdy/core/hpack/hpack_huffman_table.h
@@ -9,8 +9,8 @@ #include <cstdint> #include <vector> +#include "absl/strings/string_view.h" #include "net/third_party/quiche/src/common/platform/api/quiche_export.h" -#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" #include "net/third_party/quiche/src/spdy/core/hpack/hpack_constants.h" namespace spdy { @@ -45,10 +45,10 @@ // Encodes the input string to the output stream using the table's Huffman // context. - void EncodeString(quiche::QuicheStringPiece in, HpackOutputStream* out) const; + void EncodeString(absl::string_view in, HpackOutputStream* out) const; // Returns the encoded size of the input string. - size_t EncodedSize(quiche::QuicheStringPiece in) const; + size_t EncodedSize(absl::string_view in) const; // Returns the estimate of dynamically allocated memory in bytes. size_t EstimateMemoryUsage() const;
diff --git a/spdy/core/hpack/hpack_huffman_table_test.cc b/spdy/core/hpack/hpack_huffman_table_test.cc index f49c73d..b820f5e 100644 --- a/spdy/core/hpack/hpack_huffman_table_test.cc +++ b/spdy/core/hpack/hpack_huffman_table_test.cc
@@ -42,7 +42,7 @@ protected: GenericHuffmanTableTest() : table_(), peer_(table_) {} - std::string EncodeString(quiche::QuicheStringPiece input) { + std::string EncodeString(absl::string_view input) { std::string result; HpackOutputStream output_stream; table_.EncodeString(input, &output_stream); @@ -171,12 +171,10 @@ EXPECT_EQ(0b10011000, peer_.pad_bits()); char input_storage[] = {2, 3, 2, 7, 4}; - quiche::QuicheStringPiece input(input_storage, - QUICHE_ARRAYSIZE(input_storage)); + absl::string_view input(input_storage, QUICHE_ARRAYSIZE(input_storage)); // By symbol: (2) 00 (3) 010 (2) 00 (7) 10010 (4) 10000 (6 as pad) 1001100. char expect_storage[] = {0b00010001, 0b00101000, 0b01001100}; - quiche::QuicheStringPiece expect(expect_storage, - QUICHE_ARRAYSIZE(expect_storage)); + absl::string_view expect(expect_storage, QUICHE_ARRAYSIZE(expect_storage)); EXPECT_EQ(expect, EncodeString(input)); } @@ -258,7 +256,7 @@ for (size_t i = 0; i != 256; i++) { char c = static_cast<char>(i); char storage[3] = {c, c, c}; - quiche::QuicheStringPiece input(storage, QUICHE_ARRAYSIZE(storage)); + absl::string_view input(storage, QUICHE_ARRAYSIZE(storage)); std::string buffer_in = EncodeString(input); std::string buffer_out; DecodeString(buffer_in, &buffer_out); @@ -272,7 +270,7 @@ storage[i] = static_cast<char>(i); storage[511 - i] = static_cast<char>(i); } - quiche::QuicheStringPiece input(storage, QUICHE_ARRAYSIZE(storage)); + absl::string_view input(storage, QUICHE_ARRAYSIZE(storage)); std::string buffer_in = EncodeString(input); std::string buffer_out; DecodeString(buffer_in, &buffer_out);
diff --git a/spdy/core/hpack/hpack_output_stream.cc b/spdy/core/hpack/hpack_output_stream.cc index c53f07f..a532f0b 100644 --- a/spdy/core/hpack/hpack_output_stream.cc +++ b/spdy/core/hpack/hpack_output_stream.cc
@@ -41,7 +41,7 @@ AppendBits(prefix.bits, prefix.bit_size); } -void HpackOutputStream::AppendBytes(quiche::QuicheStringPiece buffer) { +void HpackOutputStream::AppendBytes(absl::string_view buffer) { DCHECK_EQ(bit_offset_, 0u); buffer_.append(buffer.data(), buffer.size()); }
diff --git a/spdy/core/hpack/hpack_output_stream.h b/spdy/core/hpack/hpack_output_stream.h index f99097a..b94aa0c 100644 --- a/spdy/core/hpack/hpack_output_stream.h +++ b/spdy/core/hpack/hpack_output_stream.h
@@ -9,8 +9,8 @@ #include <map> #include <string> +#include "absl/strings/string_view.h" #include "net/third_party/quiche/src/common/platform/api/quiche_export.h" -#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" #include "net/third_party/quiche/src/spdy/core/hpack/hpack_constants.h" // All section references below are to @@ -37,7 +37,7 @@ void AppendPrefix(HpackPrefix prefix); // Directly appends |buffer|. - void AppendBytes(quiche::QuicheStringPiece buffer); + void AppendBytes(absl::string_view buffer); // Appends the given integer using the representation described in // 6.1. If the internal buffer ends on a byte boundary, the prefix
diff --git a/spdy/core/hpack/hpack_static_table.cc b/spdy/core/hpack/hpack_static_table.cc index e8b07f1..c0815ce 100644 --- a/spdy/core/hpack/hpack_static_table.cc +++ b/spdy/core/hpack/hpack_static_table.cc
@@ -4,7 +4,7 @@ #include "net/third_party/quiche/src/spdy/core/hpack/hpack_static_table.h" -#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" +#include "absl/strings/string_view.h" #include "net/third_party/quiche/src/spdy/core/hpack/hpack_constants.h" #include "net/third_party/quiche/src/spdy/core/hpack/hpack_entry.h" #include "net/third_party/quiche/src/spdy/platform/api/spdy_estimate_memory_usage.h" @@ -24,8 +24,8 @@ for (const HpackStaticEntry* it = static_entry_table; it != static_entry_table + static_entry_count; ++it) { static_entries_.push_back( - HpackEntry(quiche::QuicheStringPiece(it->name, it->name_len), - quiche::QuicheStringPiece(it->value, it->value_len), + HpackEntry(absl::string_view(it->name, it->name_len), + absl::string_view(it->value, it->value_len), true, // is_static total_insertions)); HpackEntry* entry = &static_entries_.back();
diff --git a/spdy/core/hpack/hpack_static_table_test.cc b/spdy/core/hpack/hpack_static_table_test.cc index 42c6254..36eb831 100644 --- a/spdy/core/hpack/hpack_static_table_test.cc +++ b/spdy/core/hpack/hpack_static_table_test.cc
@@ -7,7 +7,7 @@ #include <set> #include <vector> -#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" +#include "absl/strings/string_view.h" #include "net/third_party/quiche/src/common/platform/api/quiche_test.h" #include "net/third_party/quiche/src/spdy/core/hpack/hpack_constants.h" @@ -39,7 +39,7 @@ HpackHeaderTable::NameToEntryMap static_name_index = table_.GetStaticNameIndex(); - std::set<quiche::QuicheStringPiece> names; + std::set<absl::string_view> names; for (auto* entry : static_index) { names.insert(entry->name()); }