Skip to content

Commit

Permalink
libfind-deal.js’s now uses a lobal instead of alocating memory
Browse files Browse the repository at this point in the history
an optimization attempt
  • Loading branch information
shlomif committed Jun 17, 2024
1 parent d2bcb98 commit 8951f03
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
3 changes: 1 addition & 2 deletions fc-solve/scripts/Makefile.to-javascript.mak
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ NEEDED_FUNCTIONS = \
fc_solve__hll_ms_rand__get_singleton \
fc_solve__hll_ms_rand__init \
fc_solve__hll_ms_rand__mod_rand \
fc_solve_user__find_deal__alloc \
fc_solve_user__find_deal__get_singleton \
fc_solve_user__find_deal__fill \
fc_solve_user__find_deal__free \
fc_solve_user__find_deal__run \


Expand Down
22 changes: 5 additions & 17 deletions fc-solve/site/wml/src/ts/find-fc-deal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,22 @@ import bigInt from "big-integer";
import * as BaseApi from "./web-fcs-api-base";

export interface ModuleWrapper extends BaseApi.ModuleWrapper {
find_deal__alloc: (...args: any) => any;
find_deal__fill: (...args: any) => any;
find_deal__free: (...args: any) => any;
find_deal__get: (...args: any) => any;
find_deal__run: (...args: any) => any;
}

export function FC_Solve_init_wrappers_with_module(Module): ModuleWrapper {
const ret = BaseApi.base_calc_module_wrapper(Module) as ModuleWrapper;
ret.find_deal__alloc = Module.cwrap(
"fc_solve_user__find_deal__alloc",
"number",
[],
);
ret.find_deal__fill = Module.cwrap(
"fc_solve_user__find_deal__fill",
"number",
["number", "string"],
);
ret.find_deal__free = Module.cwrap(
"fc_solve_user__find_deal__free",
ret.find_deal__get = Module.cwrap(
"fc_solve_user__find_deal__get_singleton",
"number",
["number"],
[],
);
ret.find_deal__run = Module.cwrap(
"fc_solve_user__find_deal__run",
Expand All @@ -43,7 +37,7 @@ export class Freecell_Deal_Finder {
constructor(args) {
const that = this;
that.module_wrapper = args.module_wrapper;
that.obj = that.module_wrapper.find_deal__alloc();
that.obj = that.module_wrapper.find_deal__get();
}

public fill(str) {
Expand All @@ -52,12 +46,6 @@ export class Freecell_Deal_Finder {
return;
}

public release() {
const that = this;
that.module_wrapper.find_deal__free(that.obj);
return;
}

public run(abs_start, abs_end_param, update_cb) {
const that = this;
const CHUNK = bigInt(1000000);
Expand Down
7 changes: 7 additions & 0 deletions fc-solve/source/board_gen/find_deal.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@ typedef struct
char ret[128];
} find_deal;

static find_deal singleton;

DLLEXPORT void *fc_solve_user__find_deal__alloc(void)
{
find_deal *const ret = SMALLOC1(ret);
return ret;
}

DLLEXPORT void *fc_solve_user__find_deal__get_singleton(void)
{
return &singleton;
}

void DLLEXPORT fc_solve_user__find_deal__free(void *obj) { free(obj); }

void DLLEXPORT fc_solve_user__find_deal__fill(
Expand Down
1 change: 1 addition & 0 deletions fc-solve/source/gen_ms_boards__find_deal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ extern long long DLLEXPORT fc_solve_find_deal_in_range(
extern DLLEXPORT void *fc_solve_user__find_deal__alloc(void);
extern void DLLEXPORT fc_solve_user__find_deal__free(void *);
extern void DLLEXPORT fc_solve_user__find_deal__fill(void *, const char *);
extern DLLEXPORT void *fc_solve_user__find_deal__get_singleton(void);
extern DLLEXPORT const char *fc_solve_user__find_deal__run(
void *, const char *, const char *);

0 comments on commit 8951f03

Please sign in to comment.