lib: avoid memory allocation on nodeprecation flag

PR-URL: https://github.com/nodejs/node/pull/50231
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Vinicius Lourenço 2023-10-30 17:48:16 -03:00 committed by GitHub
parent 8d40818d7a
commit dcaded006e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -75,6 +75,9 @@ const emittedPackageWarnings = new SafeSet();
* @param {string} base - The URL of the module that imported the package.
*/
function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
if (process.noDeprecation) {
return;
}
const pjsonPath = fileURLToPath(pjsonUrl);
if (emittedPackageWarnings.has(pjsonPath + '|' + match)) { return; }
emittedPackageWarnings.add(pjsonPath + '|' + match);
@ -101,6 +104,9 @@ const doubleSlashRegEx = /[/\\][/\\]/;
* @param {boolean} isTarget - Whether the target is a module.
*/
function emitInvalidSegmentDeprecation(target, request, match, pjsonUrl, internal, base, isTarget) {
if (process.noDeprecation) {
return;
}
const pjsonPath = fileURLToPath(pjsonUrl);
const double = RegExpPrototypeExec(doubleSlashRegEx, isTarget ? target : request) !== null;
process.emitWarning(
@ -123,6 +129,9 @@ function emitInvalidSegmentDeprecation(target, request, match, pjsonUrl, interna
* @param {string} [main] - The "main" field from the package.json file.
*/
function emitLegacyIndexDeprecation(url, packageJSONUrl, base, main) {
if (process.noDeprecation) {
return;
}
const format = defaultGetFormatWithoutErrors(url);
if (format !== 'module') { return; }
const path = fileURLToPath(url);

View File

@ -127,6 +127,11 @@ function onWarning(warning) {
// process.emitWarning(str[, type[, code]][, ctor])
// process.emitWarning(str[, options])
function emitWarning(warning, type, code, ctor) {
// Fast path to avoid memory allocation,
// this doesn't eliminate the other if a few lines below
if (process.noDeprecation && type === 'DeprecationWarning') {
return;
}
let detail;
if (type !== null && typeof type === 'object' && !ArrayIsArray(type)) {
ctor = type.ctor;