Skip to content

Commit

Permalink
refactor: Use branches for tokenizer states for 25% speed gains
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Jan 7, 2022
1 parent 71c0d8a commit 5d7a780
Show file tree
Hide file tree
Showing 3 changed files with 579 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ export class LocationInfoTokenizerMixin extends Mixin {
};

//NOTE: patch initial states for each mode to obtain token start position
for (const modeName of Object.keys(Tokenizer.MODE)) {
const state = Tokenizer.MODE[modeName];

const statesToPatch = ['_stateData', '_stateRcdata', '_stateRawtext', '_stateScriptData', '_statePlaintext'];
for (const state of statesToPatch) {
methods[state] = function (cp) {
mxn.ctLoc = mxn._getCurrentLocation();
orig[state].call(this, cp);
Expand Down

0 comments on commit 5d7a780

Please sign in to comment.