mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
errors: improve classRegExp in errors.js
PR-URL: https://github.com/nodejs/node/pull/49643 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
parent
f42a103991
commit
db8217b1bf
2 changed files with 25 additions and 1 deletions
23
benchmark/error/error-class-reg-exp.js
Normal file
23
benchmark/error/error-class-reg-exp.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
'use strict';
|
||||
|
||||
const common = require('../common.js');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
n: [1e5],
|
||||
}, {
|
||||
flags: ['--expose-internals'],
|
||||
});
|
||||
|
||||
const instances = Array.from({ length: 1000 }).map(() => 'Uint8Array');
|
||||
|
||||
function main({ n }) {
|
||||
const {
|
||||
codes: {
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
},
|
||||
} = require('internal/errors');
|
||||
bench.start();
|
||||
for (let i = 0; i < n; ++i)
|
||||
new ERR_INVALID_ARG_TYPE('target', instances, 'test');
|
||||
bench.end(n);
|
||||
}
|
|
@ -66,7 +66,8 @@ const isWindows = process.platform === 'win32';
|
|||
const messages = new SafeMap();
|
||||
const codes = {};
|
||||
|
||||
const classRegExp = /^([A-Z][a-z0-9]*)+$/;
|
||||
const classRegExp = /^[A-Z][a-zA-Z0-9]*$/;
|
||||
|
||||
// Sorted by a rough estimate on most frequently used entries.
|
||||
const kTypes = [
|
||||
'string',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue