mirror of
https://github.com/tenrok/BBob.git
synced 2026-05-15 11:59:37 +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
|
||||
* @type {{}}
|
||||
*/
|
||||
const nestedTagsMap = {};
|
||||
const nestedTagsMap = new Set();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param token
|
||||
* @returns {boolean}
|
||||
*/
|
||||
const isTokenNested = (token) => {
|
||||
if (typeof nestedTagsMap[token.getValue()] === 'undefined') {
|
||||
nestedTagsMap[token.getValue()] = tokenizer.isTokenNested(token);
|
||||
const value = token.getValue();
|
||||
|
||||
if (!nestedTagsMap.has(value) && tokenizer.isTokenNested && tokenizer.isTokenNested(token)) {
|
||||
nestedTagsMap.add(value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return nestedTagsMap[token.getValue()];
|
||||
return nestedTagsMap.has(value);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param tagName
|
||||
* @returns {boolean}
|
||||
*/
|
||||
const isTagNested = (tagName) => !!nestedTagsMap[tagName];
|
||||
const isTagNested = (tagName) => Boolean(nestedTagsMap.has(tagName));
|
||||
|
||||
/**
|
||||
* @private
|
||||
|
||||
Reference in New Issue
Block a user