Add tokenLists and use in filterTokens for ~10% time reduction.

This commit is contained in:
David Anson 2015-06-12 09:37:11 -07:00
parent 096f4d7afd
commit 3e208b7bc5
2 changed files with 26 additions and 22 deletions

View file

@ -58,6 +58,7 @@ function lintContent(content, config) {
// Parse content into tokens and lines
var tokens = md.parse(content, {});
var lines = content.split(shared.newLineRe);
var tokenLists = {};
// Annotate tokens with line/lineNumber
tokens.forEach(function forToken(token) {
if (token.map) {
@ -76,10 +77,15 @@ function lintContent(content, config) {
}
});
}
if (!tokenLists[token.type]) {
tokenLists[token.type] = [];
}
tokenLists[token.type].push(token);
});
// Create parameters for rules
var params = {
"tokens": tokens,
"tokenLists": tokenLists,
"lines": lines
};
// Merge rules/tags and sanitize config