maskit commented on code in PR #11396:
URL: https://github.com/apache/trafficserver/pull/11396#discussion_r1617621611


##########
src/proxy/hdrs/XPACK.cc:
##########
@@ -559,7 +578,50 @@ XpackDynamicTableStorage::write(const char *name, uint32_t 
name_len, const char
 }
 
 void
-XpackDynamicTableStorage::erase(uint32_t name_len, uint32_t value_len)
+XpackDynamicTableStorage::erase(uint32_t to_erase)
 {
-  this->_tail = (this->_tail + (name_len + value_len)) % this->_data_size;
+  // Ensure that _tail is not overcoming _head.
+  ink_release_assert(to_erase <= this->size());
+  this->_tail = (this->_tail + to_erase) % this->_capacity;
+}
+
+uint32_t
+XpackDynamicTableStorage::size() const
+{
+  if (this->_tail <= this->_head) {
+    return this->_head - this->_tail;
+  } else {
+    return this->_capacity - this->_tail + this->_head;
+  }
+}
+bool
+XpackDynamicTableStorage::will_overrun(uint32_t size) const
+{
+  if (this->_head == this->_capacity - 1) {
+    return size > this->_capacity;
+  }
+  return size > (this->_capacity - this->_head);
+}
+
+bool
+XpackDynamicTableStorage::update_maximum_size(uint32_t new_maximum_size)
+{
+  if (new_maximum_size <= this->_capacity) {
+    // We never shrink our memory for the data storage because we don't support
+    // arbitrary eviction from it. The XpackDynamicTable class keeps track of
+    // field sizes and therefore can evict properly.
+    return true;
+  }
+  uint32_t const new_data_size = new_maximum_size * 2;
+  uint8_t       *new_data      = reinterpret_cast<uint8_t 
*>(ats_malloc(new_data_size));

Review Comment:
   Why don't you use `realloc()`? If we are lucky data copy (memcpy) doesn't 
happen.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to