memoize parsed text labels
This commit is contained in:
parent
529ad1d4bd
commit
65b6a343d1
3 changed files with 9 additions and 5 deletions
|
|
@ -6,6 +6,7 @@ import { parse as parseLabel, SyntaxError } from "./label_parser";
|
|||
import { Connections } from "./detect_connections";
|
||||
import { HISTORY_RADIUS } from "../VisualEditor/parameters";
|
||||
import { VisualEditorState } from "@/VisualEditor/VisualEditor";
|
||||
import { memoize } from "@/App/util";
|
||||
|
||||
export type TraceableError = {
|
||||
shapeUid: string;
|
||||
|
|
@ -13,6 +14,8 @@ export type TraceableError = {
|
|||
data?: any;
|
||||
}
|
||||
|
||||
export const cachedParseLabel = memoize(parseLabel);
|
||||
|
||||
function addEvent(events: EventTrigger[], e: EventTrigger, textUid: string) {
|
||||
const haveEvent = events.find(({event}) => event === e.event);
|
||||
if (haveEvent) {
|
||||
|
|
@ -229,7 +232,7 @@ export function parseStatechart(state: VisualEditorState, conns: Connections): [
|
|||
for (const text of textsSorted) {
|
||||
let parsed: ParsedText;
|
||||
try {
|
||||
parsed = parseLabel(text.text); // may throw
|
||||
parsed = cachedParseLabel(text.text); // may throw
|
||||
parsed.uid = text.uid;
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue