Skip to content

Commit

Permalink
perf: replace parseInt with Number (#4289)
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Sep 19, 2022
1 parent 4109b03 commit 9d9d62c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
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

0 comments on commit 9d9d62c

Please sign in to comment.