Use loop for acceptParams by blakeembrey · Pull Request #6066 · expressjs/express (original) (raw)
Using a loop here would improve performance for parsing over splitting into an array and iterating over it, then splitting some more. If we prefer the overall split on ; for readability though, we can still avoid the second split by using indexOf instead. There's also some slices and trim that could be avoided for extra performance but it seemed a little overkill for this function.
Finally, given the code is only used here:
| if (key) { |
|---|
| this.set('Content-Type', normalizeType(key).value); |
| obj[key](req, this, next); |
| } else if (obj.default) { |
| obj.default(req, this, next) |
| } else { |
| next(createError(406, { |
| types: normalizeTypes(keys).map(function (o) { return o.value }) |
| })) |
| } |
. If we avoid exporting these utils to users we can just return value only and avoid the rest of the processing entirely.
closes https://github.com/expressjs/security-triage/issues/24