Skip to content

Commit

Permalink
[load-time-optimization] improve expand-moves
Browse files Browse the repository at this point in the history
We did not use all-of “fcs-validate” so capitalize-cards.ts was extracted.

Also see https://www.shlomifish.org/meta/FAQ/site_loads_quickly.xhtml
  • Loading branch information
shlomif committed Jun 14, 2024
1 parent 4018948 commit 0f58d96
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 53 deletions.
2 changes: 1 addition & 1 deletion fc-solve/site/wml/lib/make/main.mak
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ $(DEST_LIBFREECELL_SOLVER_JS_MEM__ASMJS): %: $(ASMJS_STAMP)

FCS_VALID_DEST = $(DEST_JS_DIR)/fcs-validate.js

TYPESCRIPT_basenames = chart-using-flot--4fc-intractable.js chart-using-flot--int128-opt.js expand-moves-ui.js fcs-base-ui.js fcs-chart--base.js fcs-validate.js find-fc-deal-ui.js find-fc-deal.js french-cards.js generic-tests-driver.js prange.js s2ints_js.js tests/fcs-common-constants.js tests/fcs-core.js tests/fcs-ui.js tests/fcs-validate.js toggle_sect.js toggler.js web-fc-solve--expand-moves--mega-test.js web-fc-solve--expand-moves.js web-fc-solve-ui.js web-fc-solve.js web-fcs-api-base.js web-fcs-tests-strings.js
TYPESCRIPT_basenames = capitalize-cards.js chart-using-flot--4fc-intractable.js chart-using-flot--int128-opt.js expand-moves-ui.js fcs-base-ui.js fcs-chart--base.js fcs-validate.js find-fc-deal-ui.js find-fc-deal.js french-cards.js generic-tests-driver.js prange.js s2ints_js.js tests/fcs-common-constants.js tests/fcs-core.js tests/fcs-ui.js tests/fcs-validate.js toggle_sect.js toggler.js web-fc-solve--expand-moves--mega-test.js web-fc-solve--expand-moves.js web-fc-solve-ui.js web-fc-solve.js web-fcs-api-base.js web-fcs-tests-strings.js

TYPESCRIPT_DEST_FILES = $(patsubst %.js,$(OUT_PREF)/%.js,$(TYPESCRIPT_basenames))
TYPESCRIPT_DEST_FILES__NODE = $(patsubst %.js,lib/for-node/js/%.js,$(TYPESCRIPT_basenames))
Expand Down
49 changes: 49 additions & 0 deletions fc-solve/site/wml/src/ts/capitalize-cards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
export class BoardTextLine {
private newline: string;
private comment: string;
private prefix: string;
private content: string;
constructor(public line: string) {
const that = this;
const m1 = line.match(/^([^\n\r]*)([\n\r]*)$/);
that.newline = m1[2];
let l = m1[1];
if (m1[1].match(/#/)) {
const m2 = m1[1].match(/^(.*?)(#.*)/);
that.comment = m2[2];
l = m2[1];
} else {
that.comment = "";
}
if (l.match(/:/)) {
const m3 = l.match(/^([^:]*:)(.*)/);
that.prefix = m3[1];
that.content = m3[2];
} else {
that.prefix = "";
that.content = l;
}
return;
}
public getContent(): string {
return this.content;
}
public capitalize(): string {
const that = this;
const ret =
that.prefix +
that.getContent().toUpperCase() +
that.comment +
that.newline;
return ret;
}
}

export function capitalize_cards(board: string): string {
return board
.match(/[^\n]*\n?/g)
.map((l) => {
return new BoardTextLine(l).capitalize();
})
.join("");
}
2 changes: 1 addition & 1 deletion fc-solve/site/wml/src/ts/fcs-base-ui.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jq_querystring } from "./jq_qs";
import * as BaseApi from "./web-fcs-api-base";
import { capitalize_cards } from "./fcs-validate";
import { capitalize_cards } from "./capitalize-cards";

const entityMap = {
'"': """,
Expand Down
51 changes: 1 addition & 50 deletions fc-solve/site/wml/src/ts/fcs-validate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { perl_range } from "./prange";
import { rank_re, suits__int_to_str, suit_re } from "./french-cards";
import { BoardTextLine, capitalize_cards } from "./capitalize-cards";

// Adapted from http://www.inventpartners.com/javascript_is_int - thanks.
function is_int(input: number): boolean {
Expand Down Expand Up @@ -68,56 +69,6 @@ class Card {
}
}

class BoardTextLine {
private newline: string;
private comment: string;
private prefix: string;
private content: string;
constructor(public line: string) {
const that = this;
const m1 = line.match(/^([^\n\r]*)([\n\r]*)$/);
that.newline = m1[2];
let l = m1[1];
if (m1[1].match(/#/)) {
const m2 = m1[1].match(/^(.*?)(#.*)/);
that.comment = m2[2];
l = m2[1];
} else {
that.comment = "";
}
if (l.match(/:/)) {
const m3 = l.match(/^([^:]*:)(.*)/);
that.prefix = m3[1];
that.content = m3[2];
} else {
that.prefix = "";
that.content = l;
}
return;
}
public getContent(): string {
return this.content;
}
public capitalize(): string {
const that = this;
const ret =
that.prefix +
that.getContent().toUpperCase() +
that.comment +
that.newline;
return ret;
}
}

export function capitalize_cards(board: string): string {
return board
.match(/[^\n]*\n?/g)
.map((l) => {
return new BoardTextLine(l).capitalize();
})
.join("");
}

class Column {
constructor(private cards: Card[]) {}

Expand Down
3 changes: 2 additions & 1 deletion fc-solve/site/wml/src/ts/tests/fcs-validate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { capitalize_cards } from "../capitalize-cards";

import {
BoardParseResult,
ErrorLocationType,
capitalize_cards,
fcs_js__card_from_string,
fcs_js__column_from_string,
fcs_js__foundations_from_string,
Expand Down

0 comments on commit 0f58d96

Please sign in to comment.