Skip to content

refactor: move getCharset helper to only usage#707

Open
Phillip9587 wants to merge 1 commit intoexpressjs:masterfrom
Phillip9587:move-get-charset
Open

refactor: move getCharset helper to only usage#707
Phillip9587 wants to merge 1 commit intoexpressjs:masterfrom
Phillip9587:move-get-charset

Conversation

@Phillip9587
Copy link
Member

@Phillip9587 Phillip9587 commented Feb 23, 2026

...and uses optional chaining. In theory it short-circuits faster and by that avoids the empty string allocation and .toLowerCase() call. But this is only in theory and probably highly optimized in engines.

Same ideas as @Ayoub-Mabrouk in #557.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors charset extraction by moving the getCharset helper from the shared lib/utils.js module into lib/read.js, where it is exclusively used, and updating the implementation to use optional chaining to avoid unnecessary string work when no charset is present.

Changes:

  • Remove getCharset (and its content-type dependency) from lib/utils.js exports.
  • Add a local getCharset implementation to lib/read.js and inline the content-type dependency there.
  • Switch charset normalization to charset?.toLowerCase() to avoid allocating '' and lowercasing when charset is absent.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/utils.js Removes getCharset helper and the content-type import from the shared utils export surface.
lib/read.js Adds content-type dependency and reintroduces getCharset locally for request charset parsing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants