mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-08-12 13:21:25 +00:00
Params was a std::multimap, which sorts by parameter name. Parsing a query string therefore threw away the order it arrived in, and building one back out of Params handed the caller an alphabetised query rather than the one they wrote. ClientImpl::send() takes that path whenever a request carries Params without a query already in its path, so a caller signing its query string could not reproduce the order it asked for. normalize_query_string() exists in part to work around exactly this. Generalize the container #2520 introduced for Headers into detail::insertion_ordered_multimap<Mapped, KeyEqual> and alias both types to it. Params passes std::equal_to, so parameter names stay case-sensitive, while Headers keeps matching field names case-insensitively. The name says insertion_ordered because in STL vocabulary std::multimap is the ordered one, which is the reading this change exists to correct. This is a correctness change, not a performance one. Measured on the real paths against the previous implementation, parse_query_text() over eight parameters goes 931.5ns -> 935.1ns and params_to_query_str() 374.7ns -> 377.2ns; both are inside the run-to-run noise. The container is a small share of that work, most of which is the string building in decode_query_component(). Params picks up the same API changes Headers took in #2520: iterators follow std::vector rules, value_type is std::pair<std::string, std::string>, and insert(hint, value) is gone. Headers itself becomes an alias rather than a class, so the names it appears in mangle differently again; #2520 has not shipped in a release yet, so this costs nothing on top of the break already there.