HarshMehta112 opened a new pull request, #3416:
URL: https://github.com/apache/dubbo-go/pull/3416
### Description
Fixes #3405
Summary
`canonicalizeContentType` already had a fast path for parameter-free types
like `application/json`, but content types with ; `charset=utf-8` fell through
to `mime.ParseMediaType + mime.FormatMediaType` on every
request — allocating even when the value was already canonical.
This PR adds a second fast path that handles the common case of a single ;
`charset=<token>` parameter without invoking the MIME parser:
- If the charset value is already lowercase, returns the original string
unchanged (zero allocs).
- If the charset value needs lowercasing (e.g. `UTF-8`), builds the result
with a single string concat instead of going through the full parse/format
cycle.
- All other cases (non-charset params, multiple params, quoted values,
malformed input) fall through to `canonicalizeContentTypeSlow` unchanged.
Two helpers extracted from the inline logic: `isSimpleMediaType`
(byte-loop, no allocs) and `isSimpleToken` (same).
Changes
- `protocol/triple/triple_protocol/protocol.go`: refactored fast path,
added charset fast path, added isSimpleMediaType / isSimpleToken
- `protocol/triple/triple_protocol/protocol_test.go`: added fast-path test
cases; moved b.ReportAllocs() before loop; added charset canonical, charset
uppercase, non-charset param sub-benchmarks
### Checklist
- [x] go test ./protocol/triple/triple_protocol/ passes (528 tests)
- [x] TestCanonicalizeContentType covers both fast-path and slow-path cases
- [x] I confirm the target branch is `develop`
- [x] Code has passed local testing
- [x] I have added tests that prove my fix is effective or that my feature
works
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]