Skip to content

get_header_value performs double lookup on unordered_multimap #1125

@mispritt

Description

@mispritt

In http_request.h, get_header_value is currently implemented as:

if (headers.count(key))
{
    return headers.find(key)->second;
}

When headers is a ci_map (std::unordered_multimap), this results in two independent
lookups. In particular, count() may traverse all elements with the given
key, followed by another lookup in find().

Unless there is a specific reason for this, the same behaviour can be
achieved with a single lookup:

auto it = headers.find(key);
if (it != headers.end())
{
    return it->second;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions