Skip to content

Commit

Permalink
improve performance (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored Dec 4, 2022
1 parent bf73ac3 commit 005053d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions benchmarks/warn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

const { Suite } = require('benchmark')
const warning = require('..')()

warning.create('FastifyWarning', 'FST_ERROR_CODE_1', 'message')
warning.create('FastifyWarning', 'FST_ERROR_CODE_2', 'message')
warning.create('FastifyWarning', 'FST_ERROR_CODE_3', 'message')
new Suite()
.add('warn', function () {
warning.emit('FST_ERROR_CODE_1')
warning.emit('FST_ERROR_CODE_3')
})
.on('cycle', function (event) {
console.log(String(event.target))
})
.run()
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ function processWarning () {
}

function emit (code, a, b, c) {
if (codes[code] === undefined) throw new Error(`The code '${code}' does not exist`)
if (emitted.get(code) === true) return
if (codes[code] === undefined) throw new Error(`The code '${code}' does not exist`)
emitted.set(code, true)

const warning = codes[code](a, b, c)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
},
"homepage": "https://github.com/fastify/fastify-warning#readme",
"devDependencies": {
"benchmark": "^2.1.4",
"jest": "^29.0.1",
"standard": "^17.0.0",
"tap": "^16.3.0",
Expand Down

0 comments on commit 005053d

Please sign in to comment.