Skip to content

urlapi: do not keep an internal port string#22167

Closed
icing wants to merge 3 commits into
curl:masterfrom
icing:urlapi-no-port-string
Closed

urlapi: do not keep an internal port string#22167
icing wants to merge 3 commits into
curl:masterfrom
icing:urlapi-no-port-string

Conversation

@icing

@icing icing commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

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)

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)
@github-actions github-actions Bot added the URL label Jun 25, 2026
Comment thread lib/urlapi-int.h Outdated
Comment thread lib/urlapi-int.h Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 *port field and associated allocation/free/duplication logic.
  • Track explicit port presence via port_present and store the numeric port in uint16_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.

Comment thread lib/urlapi.c Outdated
@bagder bagder closed this in 26c6a4d Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants