Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: precompute isEssence for RegExp of content-type-parser method compareRegExpContentType #4481

Merged
merged 1 commit into from Dec 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/contentTypeParser.js
Expand Up @@ -70,6 +70,7 @@ ContentTypeParser.prototype.add = function (contentType, opts, parserFn) {
if (contentTypeIsString) {
this.parserList.unshift(new ParserListItem(contentType))
} else {
contentType.isEssence = contentType.source.indexOf(';') === -1
this.parserRegExpList.unshift(contentType)
}
this.customParsers.set(contentType.toString(), parser)
Expand Down Expand Up @@ -389,7 +390,7 @@ function compareContentType (contentType, parserListItem) {
}

function compareRegExpContentType (contentType, essenceMIMEType, regexp) {
if (regexp.source.indexOf(';') === -1) {
if (regexp.isEssence) {
// we do essence check
return regexp.test(essenceMIMEType)
} else {
Expand Down