ammachado opened a new pull request, #28647:
URL: https://github.com/apache/camel/pull/28647

   # Description
   
   [CAMEL-26388](https://issues.apache.org/jira/browse/CAMEL-26388), tier 1 
item #4 of [CAMEL-25132](https://issues.apache.org/jira/browse/CAMEL-25132).
   
   `CamelContext.getEndpoint(String)` calls `URISupport.textBlockToSingleLine` 
for every uri that is not normalized yet. It ran `uri.lines()` with an 
`AtomicBoolean`, a `StringJoiner` and per-line concatenation even for 
`direct:foo`. CAMEL-25132 measured this at about 12% of all allocation in a 
`ProducerTemplate` loop.
   
   For a uri without `\n` or `\r`, `lines()` gives one line `l` and the method 
returns `trim(trim(l) + " ")`, which is `l.trim()` whether or not the line has 
a `?`. So the fast path returns `uri.trim()`, which is the same instance when 
there is nothing to trim. Both `\n` and `\r` are checked because `lines()` 
splits on either.
   
   Tests in `URISupportTest`:
   - `testTextBlockToSingleLine`: text blocks keep the context-path as-is and 
trim the query lines, also with `\r\n` (no test covered this method before).
   - `testTextBlockToSingleLineWithoutLineBreak`: a single line is only 
trimmed, white space inside it is kept, and a uri that needs no change comes 
back as the same instance. That last assertion fails before this change.
   
   Verified: `URISupportTest` (79 tests) and the camel-core tests around 
`getEndpoint` and text block uris (`UriAsJava17TextBlockTest`, 
`DefaultCamelContextTest`, `EndpointHelperTest`, `*EndpointUri*Test` and 
others, 82 tests). I did not benchmark this change myself.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
     Not from the root folder: I built and installed the changed module 
(camel-util), ran `mvn formatter:format impsort:sort` on the changed modules, 
and `git status` was clean afterwards.
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   
   The code and this description were written with Claude Code (Claude Opus 
5.5) and reviewed by me.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code) on behalf of 
Adriano Machado (@ammachado)
   
   _This was generated by an AI agent and may contain inaccuracies. Please 
verify before relying on it._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to