- 
    Task 
- 
    Resolution: Unresolved
- 
    P3: Somewhat important 
- 
    None
- 
    None
- 
    None
- 
        
- 
        8
- 
        Foundation PM Staging
This issue stems from this review comment.
User may use the string (QAnyStringView) function overloads, and internally QHttpHeaders checks if the provided string can be mapped to a WellKnownHeader enum.
Currently the code first normalizes the value, and then attempts to map that value to WellKnownHeader. The mapping-attempt could be done before value normalization => we don't unnecessarily normalize the value and allocate memory for it.
However implementing this optimisation is not trivial. The straightforward approach:
struct HeaderName
{
	 // ...
    explicit HeaderName(QAnyStringView name)
    {
        if (auto h = HeaderName::toWellKnownHeader(name)) // [A] pass directly as QASV
            data = *h;
        else
            data = normalizedName(name);
    }
    // Returns an enum corresponding with the 'name' if possible. Uses binary search (O(logN)).
    static std::optional<QHttpHeaders::WellKnownHeader> toWellKnownHeader(QAnyStringView name) noexcept
    {
        auto indexesBegin = std::cbegin(orderedHeaderNameIndexes);
        auto indexesEnd = std::cend(orderedHeaderNameIndexes);
        auto result = std::lower_bound(indexesBegin, indexesEnd, name, ByIndirectHeaderName{});
		  // [B] modify to case insensitive comparison 
        if (result != indexesEnd
            && QAnyStringView::compare(name, headerNames.viewAt(*result), Qt::CaseInsensitive) == 0) {
            return static_cast<QHttpHeaders::WellKnownHeader>(*result);
        }
        return std::nullopt;
    }
    // ...
};
struct ByIndirectHeaderName
{
	// [C] QASV operator() overload:
   constexpr bool operator()(quint8 lhs, QAnyStringView rhs) const noexcept
   {
        return QAnyStringView::compare(headerNames.viewAt(lhs), rhs, Qt::CaseInsensitive) < 0;
   }
};
works, but according to tst_bench_qhttpheaders, the performance actually decreases because we do case-insensitive comparisons. So some additional mechanism would be needed.