On 26. 11. 2026 09:51, Ruediger Pluem via dev wrote:
On 11/20/26 2:27 PM, Yann Ylavic wrote:
On Thu, Nov 19, 2026 at 2:44 PM Branko Čibej via dev<[email protected]> wrote:
On 18. 11. 2026 09:59, Ruediger Pluem via dev wrote:
On 11/16/26 4:10 PM, Yann Ylavic wrote:
diff -ru a/uri/apr_uri.c b/uri/apr_uri.c
--- a/uri/apr_uri.c 2026-11-16 16:02:56.759516227 +0100
+++ b/uri/apr_uri.c 2026-11-16 16:02:56.784734796 +0100
@@ -999,6 +999,7 @@
if (have_zone_id) {
percent_decode_scope_zone_id(uptr->hostname);
}
+ uptr->port = apr_uri_port_of_scheme(uptr->scheme);
goto deal_with_path;
}
uptr->hostname = apr_pstrmemdup(p,
Sounds sensible. Maybe AI can help us generate all the test cases such that
we can be sure it works and keeps working after changes.
See attached "apr-uri-default-port.patch" (including tests).
I have an implementation ready that uses a generated minimal perfect hash
function for lookups. The hash function is O(strlen(key)) to calculate the hash
of the lookup key and O(1) to find the scheme. Except for the very first scheme
in in the list, where linear lookup needs just a single strcasecmp(), it's
faster by up to 5 times from the current lookup.
This adds quite some infrastructure to APR (Python generator,
template, generated .inc, uri_schemes.h, non-static apr__uri_schemes),
what about something like the attached "apr-uri-port-of-scheme.patch"
(including tests)?
It's simpler (IMHO), and in my testing it works faster (probably due
to the multiplies for the perfect hashing) and also avoids both
strcasecmp() (current code) and tolower() (your patch) which are
locale dependent.
Can't we even speed up things more for https by
Instead of
case 'h': case 'H':
if (!apr_cstr_casecmp(scheme_str, "http"))
return APR_URI_HTTP_DEFAULT_PORT;
if (!apr_cstr_casecmp(scheme_str, "https"))
return APR_URI_HTTPS_DEFAULT_PORT;
break;
using
case 'h': case 'H':
if (!apr_cstr_casecmpn(scheme_str, "http", 4))
switch (scheme_str[4]) {
case '\0':
return APR_URI_HTTP_DEFAULT_PORT;
case 's': case: 'S':
return APR_URI_HTTPS_DEFAULT_PORT;
}
break;
Oh yes, this probably shaves a few nanoseconds off the search, but also
matches "httpsugar". :)
-- Brane
P.S.: See my "unreadable, unmaintainable" rant above -- this just proves
that adding bugs to a switch-based implementation is way easier than not
adding them.