urlapi: do not keep an internal port string#22167
Closed
icing wants to merge 3 commits into
Closed
Conversation
Do not allocated an internal port string, just keep and number and a bit if it is present. Format the port string in a local buffer when someone asks for it and copy that. This avoid the format/alloc penalty when parsing URLs and no one ever asking for the port string. (And there will be a method to get the uint16_t value directly in another PR)
bagder
reviewed
Jun 25, 2026
There was a problem hiding this comment.
Pull request overview
This PR optimizes libcurl’s internal URL (CURLU) representation by removing the heap-allocated port string and instead storing only a numeric uint16_t port plus a “present” bit, formatting the port string only on demand. This reduces allocations and formatting work during URL parsing when callers never request the port string.
Changes:
- Remove the internal
char *portfield and associated allocation/free/duplication logic. - Track explicit port presence via
port_presentand store the numeric port inuint16_t portnum. - Format the port into a local buffer only when constructing a URL string or returning
CURLUPART_PORT.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/urlapi.c | Drops persistent port string storage; formats port lazily and updates same-origin/URL-get logic to use port_present. |
| lib/urlapi-int.h | Updates internal struct Curl_URL to replace char *port with uint16_t portnum + BIT(port_present). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bagder
approved these changes
Jun 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Do not allocated an internal port string, just keep and number and a bit if it is present. Format the
port string in a local buffer when someone asks for it and copy that.
This avoid the format/alloc penalty when parsing URLs and no one ever asking for the port string.
(And there will be a method to get the uint16_t value directly in another PR)