mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Remove helpers.deepFreeze and call Object.freeze only on things that need it for ~11% time reduction measured via profile-fixture.mjs on Apple Silicon M1.
This commit is contained in:
parent
b6471fba31
commit
936c876810
5 changed files with 110 additions and 97 deletions
|
|
@ -1153,28 +1153,6 @@ function getNextChildToken(parentToken, childToken, nextType, nextNextType) {
|
|||
}
|
||||
module.exports.getNextChildToken = getNextChildToken;
|
||||
|
||||
/**
|
||||
* Calls Object.freeze() on an object and its children.
|
||||
*
|
||||
* @param {Object} obj Object to deep freeze.
|
||||
* @returns {Object} Object passed to the function.
|
||||
*/
|
||||
function deepFreeze(obj) {
|
||||
const pending = [ obj ];
|
||||
let current = null;
|
||||
while ((current = pending.shift())) {
|
||||
Object.freeze(current);
|
||||
for (const name of Object.getOwnPropertyNames(current)) {
|
||||
const value = current[name];
|
||||
if (value && (typeof value === "object")) {
|
||||
pending.push(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
module.exports.deepFreeze = deepFreeze;
|
||||
|
||||
/**
|
||||
* Expands a path with a tilde to an absolute path.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue