Skip to content

Commit

Permalink
(v3.x) perf: only check for isEssence once in RegExp for content-type…
Browse files Browse the repository at this point in the history
…-parser (#4481) (#4497)
  • Loading branch information
climba03003 committed Jan 6, 2023
1 parent c172cae commit e4e8393
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/contentTypeParser.js
Expand Up @@ -72,6 +72,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 @@ -396,7 +397,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

0 comments on commit e4e8393

Please sign in to comment.