mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-20 20:00:33 +03:00
perf(parser): cache nested tokens in Set to prevent deoptimization (#83)
This commit is contained in:
committed by
GitHub
parent
70ff2e6660
commit
cad0e9e7f4
@@ -49,23 +49,31 @@ const parse = (input, opts = {}) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache for nested tags checks
|
* Cache for nested tags checks
|
||||||
* @type {{}}
|
|
||||||
*/
|
*/
|
||||||
const nestedTagsMap = {};
|
const nestedTagsMap = new Set();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param token
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
const isTokenNested = (token) => {
|
const isTokenNested = (token) => {
|
||||||
if (typeof nestedTagsMap[token.getValue()] === 'undefined') {
|
const value = token.getValue();
|
||||||
nestedTagsMap[token.getValue()] = tokenizer.isTokenNested(token);
|
|
||||||
|
if (!nestedTagsMap.has(value) && tokenizer.isTokenNested && tokenizer.isTokenNested(token)) {
|
||||||
|
nestedTagsMap.add(value);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nestedTagsMap[token.getValue()];
|
return nestedTagsMap.has(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param tagName
|
* @param tagName
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
const isTagNested = (tagName) => !!nestedTagsMap[tagName];
|
const isTagNested = (tagName) => Boolean(nestedTagsMap.has(tagName));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
|||||||
Reference in New Issue
Block a user