moonchen commented on code in PR #13455:
URL: https://github.com/apache/trafficserver/pull/13455#discussion_r3899238752
##########
src/proxy/hdrs/MIME.cc:
##########
@@ -1361,10 +1407,59 @@ mime_field_create(HdrHeap *heap, MIMEHdrImpl *mh)
return field;
}
+MIMEField *
+mime_field_create_for_name(HdrHeap *heap, MIMEHdrImpl *mh, std::string_view
name)
+{
+ if (mh->m_fblock_list_tail->m_freetop < MIME_FIELD_BLOCK_SLOTS) {
+ return mime_field_create(heap, mh);
+ }
+
+ int last_dup_slot = -1;
+
+ if (MIMEField *last_dup = name.empty() ? nullptr : mime_hdr_field_find(mh,
name); last_dup != nullptr) {
+ while (last_dup->m_next_dup != nullptr) {
+ last_dup = last_dup->m_next_dup;
+ }
+ last_dup_slot = mime_hdr_field_slotnum(mh, last_dup);
+ ink_release_assert(last_dup_slot >= 0);
+ }
+
+ if (mh->m_free_slot == MIME_FIELD_FREE_SLOT_UNINITIALIZED) {
Review Comment:
Could we avoid `mime_hdr_field_find()` and walking the duplicate chain when
`m_free_slot == MIME_FIELD_FREE_SLOT_NONE`? Since the tail is full here,
`mime_field_create()` must allocate a new block, and its slot will necessarily
follow every existing duplicate. This would mean rebuilding first when
`m_free_slot == MIME_FIELD_FREE_SLOT_UNINITIALIZED`, then returning early if
the result is `NONE`.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]