Skip to content

Commit

Permalink
optimize performance
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWang15 committed Aug 19, 2021
1 parent 1a2f245 commit 0659b79
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib/classes/Marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ const defaultEventHandler: EventHandler = {
};

class Marker {
public static normalizeTextCache = {} as any;
rootElement: Element;
eventHandler: EventHandler;
highlightPainter: HighlightPainter;

state = {
lastHoverId: "",
uidToSerializedRange: {} as { [key: string]: SerializedRange },
Expand Down Expand Up @@ -86,7 +86,10 @@ class Marker {
}

private static normalizeText(s: string) {
return s.replace(/\s/g, "").toLowerCase();
if (!Marker.normalizeTextCache[s]) {
Marker.normalizeTextCache[s] = s.replace(/\s/g, "").toLowerCase();
}
return Marker.normalizeTextCache[s];
}

private static isBlackListedElementNode(element: Node | null) {
Expand Down

0 comments on commit 0659b79

Please sign in to comment.