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

Replace parseInt with Number at get 6% boost #4289

Merged
merged 1 commit into from Sep 19, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/contentTypeParser.js
Expand Up @@ -189,7 +189,7 @@ function rawBody (request, reply, options, parser, done) {
const limit = options.limit === null ? parser.bodyLimit : options.limit
const contentLength = request.headers['content-length'] === undefined
? NaN
: Number.parseInt(request.headers['content-length'], 10)
: Number(request.headers['content-length'])

if (contentLength > limit) {
reply.send(new FST_ERR_CTP_BODY_TOO_LARGE())
Expand Down
4 changes: 2 additions & 2 deletions lib/reply.js
Expand Up @@ -292,7 +292,7 @@ Reply.prototype.removeTrailer = function (key) {
}

Reply.prototype.code = function (code) {
const intValue = parseInt(code)
const intValue = Number(code)
if (isNaN(intValue) || intValue < 100 || intValue > 599) {
throw new FST_ERR_BAD_STATUS_CODE(code || String(code))
}
Expand Down Expand Up @@ -562,7 +562,7 @@ function onSendEnd (reply, payload) {
const contentLength = reply[kReplyHeaders]['content-length']
if (!contentLength ||
(req.raw.method !== 'HEAD' &&
parseInt(contentLength, 10) !== Buffer.byteLength(payload)
Number(contentLength) !== Buffer.byteLength(payload)
)
) {
reply[kReplyHeaders]['content-length'] = '' + Buffer.byteLength(payload)
Expand Down
2 changes: 1 addition & 1 deletion lib/server.js
Expand Up @@ -331,7 +331,7 @@ function normalizeListenArgs (args) {
}

function normalizePort (firstArg) {
const port = parseInt(firstArg, 10)
const port = Number(firstArg)
return port >= 0 && !Number.isNaN(port) ? port : 0
}

Expand Down
4 changes: 2 additions & 2 deletions test/internals/reply-serialize.test.js
Expand Up @@ -231,7 +231,7 @@ test('Reply#getSerializationFunction', t => {
(req, reply) => {
const { id } = req.params

if (parseInt(id) === 1) {
if (Number(id) === 1) {
const serialize4xx = reply.getSerializationFunction('4xx')
const serialize201 = reply.getSerializationFunction(201)
const serializeUndefined = reply.getSerializationFunction(undefined)
Expand Down Expand Up @@ -308,7 +308,7 @@ test('Reply#getSerializationFunction', t => {
(req, reply) => {
const { id } = req.params

if (parseInt(id) === 1) {
if (Number(id) === 1) {
const serialize = reply.compileSerializationSchema(schemaObj)

t.type(serialize, Function)
Expand Down