On 16. 11. 2026 16:10, Yann Ylavic wrote:
On Mon, Nov 16, 2026 at 3:19 PM Rainer Jung<[email protected]> wrote:
Can't we delay apr_uri_port_of_scheme() until we know there is no ":port" still?
Due to the use of goto, the code jumps a bit back and forth. So I found
it more robust to set immediately a default port when the scheme is
found and then overwrite it when a specific port is found than to find
all the exit points after (not necessarily below) the port detection and
then fall back to the default.
Looks like the below does it (full patch not cumulative, claude confirms).
My concern is that apr_uri_port_of_scheme() is quite slow, though the
common case is probably the one added here..

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,
--

apr_uri_port_of_scheme() could (should?) use a pre-built perfect hash or at least bsearch() in a sorted array. Yes, the current implementation is slow but it doesn't have to be. It also doesn't have to use strcasecmp(), it can tolower() the input string because scheme names are guaranteed to be ASCII-subset letters.

As for the "claude confirms" part, I'm sure it's more robust to write a test that proves a static array of strings is sorted than one that proves that Claude was right now and for all possible future changes in apr_uri_parse().

-- Brane

Reply via email to