Add QpackHeaderTable::MaxInsertSizeWithoutEvictingGivenEntry().
gfe-relnote: n/a, change to QUIC v99-only code. Protected by existing disabled gfe2_reloadable_flag_quic_enable_version_99.
PiperOrigin-RevId: 260535294
Change-Id: Ica02434e33e5a60d51d297f7837e0726dc1cbd3c
diff --git a/quic/core/qpack/qpack_header_table.cc b/quic/core/qpack/qpack_header_table.cc
index 92eb072..3c9296d 100644
--- a/quic/core/qpack/qpack_header_table.cc
+++ b/quic/core/qpack/qpack_header_table.cc
@@ -141,6 +141,28 @@
return new_entry;
}
+uint64_t QpackHeaderTable::MaxInsertSizeWithoutEvictingGivenEntry(
+ uint64_t index) const {
+ DCHECK_LE(dropped_entry_count_, index);
+
+ if (index > inserted_entry_count()) {
+ // All entries are allowed to be evicted.
+ return dynamic_table_capacity_;
+ }
+
+ // Initialize to current available capacity.
+ uint64_t max_insert_size = dynamic_table_capacity_ - dynamic_table_size_;
+
+ for (const auto& entry : dynamic_entries_) {
+ if (entry.InsertionIndex() >= index) {
+ break;
+ }
+ max_insert_size += entry.Size();
+ }
+
+ return max_insert_size;
+}
+
bool QpackHeaderTable::SetDynamicTableCapacity(uint64_t capacity) {
if (capacity > maximum_dynamic_table_capacity_) {
return false;