Skip to content

Commit 0eb37e7

Browse files
committed
reduce caching
1 parent 3de76c2 commit 0eb37e7

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/parser/lexer.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ const longWord = choiceOnlyOne(matchString("a"), matchString("n"))
116116
)
117117
.skip(spaces);
118118

119-
Parser.startCache(cache);
120-
121119
/** Parses X ala X constructions if allowed by the settings. */
122120
const xAlaX = lazy(() => {
123121
if (settings.xAlaXPartialParsing) {
@@ -131,8 +129,6 @@ const xAlaX = lazy(() => {
131129
})
132130
.map<Token>((word) => ({ type: "x ala x", word }));
133131

134-
Parser.endCache();
135-
136132
/** Parses a punctuation. */
137133
const punctuation = choiceOnlyOne(
138134
match(/[.,:;?!·\u{F199C}\u{F199D}]+/u, "punctuation")

src/parser/parser-lib.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ export class Parser<T> {
1717
readonly #parser: (src: string) => ParserResult<T>;
1818
static cache: null | Cache = null;
1919
constructor(parser: (src: string) => ParserResult<T>) {
20-
const cache = new Map<string, ParserResult<T>>();
21-
Parser.addToCache(cache);
22-
this.#parser = memoize(parser, { cache });
20+
if (Parser.cache != null) {
21+
const cache = new Map<string, ParserResult<T>>();
22+
Parser.addToCache(cache);
23+
this.#parser = memoize(parser, { cache });
24+
} else {
25+
this.#parser = parser;
26+
}
2327
}
2428
parser(src: string): ParserResult<T> {
2529
return ArrayResult.from(() => this.#parser(src));

0 commit comments

Comments
 (0)