Remove QuicInlinedVector from platform.
Internally, it was defined as absl::InlinedVector and a custom printer was added
(which this CL removes).
In Envoy, it was defined as absl::InlinedVector and a custom printer was added:
https://github.com/envoyproxy/envoy/blob/40a656d36244652b7afd97c7d8492f643c94283d/source/common/quic/platform/quic_containers_impl.h#L51-L65
In Chromium, it was defined as std::vector, and I don't see the printer (maybe
there's one in STL?).
This CL removes QuicInlinedVector, inlines absl::InlinedVector, and adds
quiche::PrintElements() to QUICHE, so that embedders do not have to provide
their custom printers. PrintElements() is based on the Envoy custom printer
implementation. However, I'm adding a helper function with std::string return
value instead of an operator<<() override because
1. an operator<<() override would need to live in either std or absl
namespace, and it is not nice to add stuff to library namespaces;
2. if Abseil ever adds an official operator<<() override, that would cause a
clash immediately, and it would be some amount of work to resolve it while
the override get upstreamed to public Abseil (internal code uses internal,
source-of-truth Abseil, other QUICHE embedders use public Abseil, so QUICHE
needs to work with both at the same time until new operator<<() gets merged
to public Abseil and that public Abseil gets rolled into QUICHE embedders).
PiperOrigin-RevId: 383833970
diff --git a/common/print_elements.h b/common/print_elements.h
new file mode 100644
index 0000000..f241a4b
--- /dev/null
+++ b/common/print_elements.h
@@ -0,0 +1,35 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef QUICHE_COMMON_PRINT_ELEMENTS_H_
+#define QUICHE_COMMON_PRINT_ELEMENTS_H_
+
+#include <ostream>
+#include <sstream>
+#include <string>
+
+#include "common/platform/api/quiche_export.h"
+
+namespace quiche {
+
+// Print elements of any iterable container that has cbegin() and cend() methods
+// and the elements have operator<<(ostream) override.
+template <typename T>
+QUICHE_EXPORT_PRIVATE inline std::string PrintElements(const T& container) {
+ std::stringstream debug_string;
+ debug_string << "{";
+ auto it = container.cbegin();
+ debug_string << *it;
+ ++it;
+ while (it != container.cend()) {
+ debug_string << ", " << *it;
+ ++it;
+ }
+ debug_string << "}";
+ return debug_string.str();
+}
+
+} // namespace quiche
+
+#endif // QUICHE_COMMON_PRINT_ELEMENTS_H_
diff --git a/quic/core/congestion_control/bbr2_sender.cc b/quic/core/congestion_control/bbr2_sender.cc
index f2199ba..09b920e 100644
--- a/quic/core/congestion_control/bbr2_sender.cc
+++ b/quic/core/congestion_control/bbr2_sender.cc
@@ -16,6 +16,7 @@
#include "quic/platform/api/quic_flag_utils.h"
#include "quic/platform/api/quic_flags.h"
#include "quic/platform/api/quic_logging.h"
+#include "common/print_elements.h"
namespace quic {
@@ -283,7 +284,8 @@
}
QUIC_DVLOG(3)
- << this << " END CongestionEvent(acked:" << acked_packets
+ << this
+ << " END CongestionEvent(acked:" << quiche::PrintElements(acked_packets)
<< ", lost:" << lost_packets.size() << ") "
<< ", Mode:" << mode_ << ", RttCount:" << model_.RoundTripCount()
<< ", BytesInFlight:" << congestion_event.bytes_in_flight
diff --git a/quic/core/frames/quic_frame.h b/quic/core/frames/quic_frame.h
index 1efe1e6..9ee4568 100644
--- a/quic/core/frames/quic_frame.h
+++ b/quic/core/frames/quic_frame.h
@@ -9,6 +9,7 @@
#include <type_traits>
#include <vector>
+#include "absl/container/inlined_vector.h"
#include "quic/core/frames/quic_ack_frame.h"
#include "quic/core/frames/quic_ack_frequency_frame.h"
#include "quic/core/frames/quic_blocked_frame.h"
@@ -133,7 +134,7 @@
// A inline size of 1 is chosen to optimize the typical use case of
// 1-stream-frame in QuicTransmissionInfo.retransmittable_frames.
-using QuicFrames = QuicInlinedVector<QuicFrame, 1>;
+using QuicFrames = absl::InlinedVector<QuicFrame, 1>;
// Deletes all the sub-frames contained in |frames|.
QUIC_EXPORT_PRIVATE void DeleteFrames(QuicFrames* frames);
diff --git a/quic/core/frames/quic_message_frame.h b/quic/core/frames/quic_message_frame.h
index ef1e070..3064ddb 100644
--- a/quic/core/frames/quic_message_frame.h
+++ b/quic/core/frames/quic_message_frame.h
@@ -5,6 +5,7 @@
#ifndef QUICHE_QUIC_CORE_FRAMES_QUIC_MESSAGE_FRAME_H_
#define QUICHE_QUIC_CORE_FRAMES_QUIC_MESSAGE_FRAME_H_
+#include "absl/container/inlined_vector.h"
#include "quic/core/quic_types.h"
#include "quic/platform/api/quic_containers.h"
#include "quic/platform/api/quic_export.h"
@@ -13,7 +14,7 @@
namespace quic {
-using QuicMessageData = QuicInlinedVector<QuicMemSlice, 1>;
+using QuicMessageData = absl::InlinedVector<QuicMemSlice, 1>;
struct QUIC_EXPORT_PRIVATE QuicMessageFrame {
QuicMessageFrame() = default;
diff --git a/quic/core/quic_packet_creator.cc b/quic/core/quic_packet_creator.cc
index cbca89d..9c4e71e 100644
--- a/quic/core/quic_packet_creator.cc
+++ b/quic/core/quic_packet_creator.cc
@@ -34,6 +34,7 @@
#include "quic/platform/api/quic_flags.h"
#include "quic/platform/api/quic_logging.h"
#include "quic/platform/api/quic_server_stats.h"
+#include "common/print_elements.h"
namespace quic {
namespace {
@@ -1522,7 +1523,7 @@
QUIC_BUG_IF(quic_bug_12398_18,
GetQuicReloadableFlag(quic_single_ack_in_packet2) &&
!frames.empty() && has_ack())
- << ENDPOINT << "Trying to flush " << frames
+ << ENDPOINT << "Trying to flush " << quiche::PrintElements(frames)
<< " when there is ACK queued";
for (const auto& frame : frames) {
QUICHE_DCHECK(frame.type == ACK_FRAME || frame.type == STOP_WAITING_FRAME)
diff --git a/quic/core/quic_path_validator.h b/quic/core/quic_path_validator.h
index ccd3a6c..9ea1554 100644
--- a/quic/core/quic_path_validator.h
+++ b/quic/core/quic_path_validator.h
@@ -7,6 +7,7 @@
#include <ostream>
+#include "absl/container/inlined_vector.h"
#include "quic/core/crypto/quic_random.h"
#include "quic/core/quic_alarm.h"
#include "quic/core/quic_alarm_factory.h"
@@ -145,7 +146,7 @@
void ResetPathValidation();
// Has at most 3 entries due to validation timeout.
- QuicInlinedVector<QuicPathFrameBuffer, 3> probing_data_;
+ absl::InlinedVector<QuicPathFrameBuffer, 3> probing_data_;
SendDelegate* send_delegate_;
QuicRandom* random_;
std::unique_ptr<QuicPathValidationContext> path_context_;
diff --git a/quic/core/quic_sent_packet_manager.cc b/quic/core/quic_sent_packet_manager.cc
index 934ee0c..fd1190b 100644
--- a/quic/core/quic_sent_packet_manager.cc
+++ b/quic/core/quic_sent_packet_manager.cc
@@ -24,6 +24,7 @@
#include "quic/platform/api/quic_flag_utils.h"
#include "quic/platform/api/quic_flags.h"
#include "quic/platform/api/quic_logging.h"
+#include "common/print_elements.h"
namespace quic {
@@ -1611,7 +1612,7 @@
<< acked_packet.packet_number
<< ", last_ack_frame_: " << last_ack_frame_
<< ", least_unacked: " << unacked_packets_.GetLeastUnacked()
- << ", packets_acked_: " << packets_acked_;
+ << ", packets_acked_: " << quiche::PrintElements(packets_acked_);
} else {
QUIC_PEER_BUG(quic_peer_bug_10750_6)
<< "Received " << ack_decrypted_level
diff --git a/quic/core/quic_types.h b/quic/core/quic_types.h
index bbe1a58..253ffcb 100644
--- a/quic/core/quic_types.h
+++ b/quic/core/quic_types.h
@@ -12,6 +12,7 @@
#include <ostream>
#include <vector>
+#include "absl/container/inlined_vector.h"
#include "quic/core/quic_connection_id.h"
#include "quic/core/quic_error_codes.h"
#include "quic/core/quic_packet_number.h"
@@ -586,7 +587,7 @@
};
// A vector of acked packets.
-using AckedPacketVector = QuicInlinedVector<AckedPacket, 2>;
+using AckedPacketVector = absl::InlinedVector<AckedPacket, 2>;
// Information about a newly lost packet.
struct QUIC_EXPORT_PRIVATE LostPacket {
@@ -603,7 +604,7 @@
};
// A vector of lost packets.
-using LostPacketVector = QuicInlinedVector<LostPacket, 2>;
+using LostPacketVector = absl::InlinedVector<LostPacket, 2>;
// Please note, this value cannot used directly for packet serialization.
enum QuicLongHeaderType : uint8_t {
diff --git a/quic/core/quic_unacked_packet_map.cc b/quic/core/quic_unacked_packet_map.cc
index 1c4e446..9f9919c 100644
--- a/quic/core/quic_unacked_packet_map.cc
+++ b/quic/core/quic_unacked_packet_map.cc
@@ -8,6 +8,7 @@
#include <limits>
#include <type_traits>
+#include "absl/container/inlined_vector.h"
#include "quic/core/quic_connection_stats.h"
#include "quic/core/quic_packet_number.h"
#include "quic/core/quic_types.h"
@@ -325,9 +326,9 @@
RemoveFromInFlight(info);
}
-QuicInlinedVector<QuicPacketNumber, 2>
+absl::InlinedVector<QuicPacketNumber, 2>
QuicUnackedPacketMap::NeuterUnencryptedPackets() {
- QuicInlinedVector<QuicPacketNumber, 2> neutered_packets;
+ absl::InlinedVector<QuicPacketNumber, 2> neutered_packets;
QuicPacketNumber packet_number = GetLeastUnacked();
for (QuicUnackedPacketMap::iterator it = begin(); it != end();
++it, ++packet_number) {
@@ -353,9 +354,9 @@
return neutered_packets;
}
-QuicInlinedVector<QuicPacketNumber, 2>
+absl::InlinedVector<QuicPacketNumber, 2>
QuicUnackedPacketMap::NeuterHandshakePackets() {
- QuicInlinedVector<QuicPacketNumber, 2> neutered_packets;
+ absl::InlinedVector<QuicPacketNumber, 2> neutered_packets;
QuicPacketNumber packet_number = GetLeastUnacked();
for (QuicUnackedPacketMap::iterator it = begin(); it != end();
++it, ++packet_number) {
diff --git a/quic/core/quic_unacked_packet_map.h b/quic/core/quic_unacked_packet_map.h
index 676f054..b8f8ffe 100644
--- a/quic/core/quic_unacked_packet_map.h
+++ b/quic/core/quic_unacked_packet_map.h
@@ -8,6 +8,7 @@
#include <cstddef>
#include <cstdint>
+#include "absl/container/inlined_vector.h"
#include "absl/strings/str_cat.h"
#include "quic/core/quic_packets.h"
#include "quic/core/quic_transmission_info.h"
@@ -69,12 +70,12 @@
// Called to neuter all unencrypted packets to ensure they do not get
// retransmitted. Returns a vector of neutered packet numbers.
- QuicInlinedVector<QuicPacketNumber, 2> NeuterUnencryptedPackets();
+ absl::InlinedVector<QuicPacketNumber, 2> NeuterUnencryptedPackets();
// Called to neuter packets in handshake packet number space to ensure they do
// not get retransmitted. Returns a vector of neutered packet numbers.
// TODO(fayang): Consider to combine this with NeuterUnencryptedPackets.
- QuicInlinedVector<QuicPacketNumber, 2> NeuterHandshakePackets();
+ absl::InlinedVector<QuicPacketNumber, 2> NeuterHandshakePackets();
// Returns true if |packet_number| has retransmittable frames. This will
// return false if all frames of this packet are either non-retransmittable or
diff --git a/quic/core/quic_write_blocked_list.h b/quic/core/quic_write_blocked_list.h
index 78efbad..54441e7 100644
--- a/quic/core/quic_write_blocked_list.h
+++ b/quic/core/quic_write_blocked_list.h
@@ -9,6 +9,7 @@
#include <cstdint>
#include <utility>
+#include "absl/container/inlined_vector.h"
#include "http2/core/priority_write_scheduler.h"
#include "quic/core/quic_packets.h"
#include "quic/platform/api/quic_bug_tracker.h"
@@ -101,7 +102,7 @@
};
// Optimized for the typical case of 2 static streams per session.
- using StreamsVector = QuicInlinedVector<StreamIdBlockedPair, 2>;
+ using StreamsVector = absl::InlinedVector<StreamIdBlockedPair, 2>;
StreamsVector::const_iterator begin() const { return streams_.cbegin(); }
diff --git a/quic/platform/api/quic_containers.h b/quic/platform/api/quic_containers.h
index be836db..eb16bfa 100644
--- a/quic/platform/api/quic_containers.h
+++ b/quic/platform/api/quic_containers.h
@@ -9,10 +9,6 @@
namespace quic {
-// A vector optimized for small sizes. Provides the same APIs as a std::vector.
-template <typename T, size_t N, typename A = std::allocator<T>>
-using QuicInlinedVector = QuicInlinedVectorImpl<T, N, A>;
-
// An ordered container optimized for small sets.
// An implementation with O(n) mutations might be chosen
// in case it has better memory usage and/or faster access.
diff --git a/quic/platform/api/quic_containers_test.cc b/quic/platform/api/quic_containers_test.cc
deleted file mode 100644
index bc255d3..0000000
--- a/quic/platform/api/quic_containers_test.cc
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright (c) 2018 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "quic/platform/api/quic_containers.h"
-
-#include "quic/platform/api/quic_test.h"
-
-using ::testing::ElementsAre;
-
-namespace quic {
-namespace test {
-namespace {
-
-TEST(QuicInlinedVectorTest, Swap) {
- {
- // Inline to inline.
- QuicInlinedVector<int, 2> self({1, 2});
- QuicInlinedVector<int, 2> other({3});
-
- self.swap(other);
-
- EXPECT_THAT(self, ElementsAre(3));
- EXPECT_THAT(other, ElementsAre(1, 2));
- }
-
- {
- // Inline to out-of-line.
- QuicInlinedVector<int, 2> self({1, 2});
- QuicInlinedVector<int, 2> other({3, 4, 5, 6});
-
- self.swap(other);
-
- EXPECT_THAT(self, ElementsAre(3, 4, 5, 6));
- EXPECT_THAT(other, ElementsAre(1, 2));
- }
-
- {
- // Out-of-line to inline.
- QuicInlinedVector<int, 2> self({1, 2, 3});
- QuicInlinedVector<int, 2> other({4, 5});
-
- self.swap(other);
-
- EXPECT_THAT(self, ElementsAre(4, 5));
- EXPECT_THAT(other, ElementsAre(1, 2, 3));
- }
-
- {
- // Out-of-line to Out-of-line.
- QuicInlinedVector<int, 2> self({1, 2, 3});
- QuicInlinedVector<int, 2> other({4, 5, 6, 7});
-
- self.swap(other);
-
- EXPECT_THAT(self, ElementsAre(4, 5, 6, 7));
- EXPECT_THAT(other, ElementsAre(1, 2, 3));
- }
-}
-
-} // namespace
-} // namespace test
-} // namespace quic