From dffdf200cc8ed18b2992acc982c0c479053f37cd Mon Sep 17 00:00:00 2001 From: biglyderv Date: Thu, 27 Mar 2025 07:34:20 -0400 Subject: [PATCH] optimize for filesize --- Makefile | 2 +- src/command.c | 7 +------ src/loader.c | 2 +- src/main.c | 9 +-------- src/main.h | 11 +++++++++++ 5 files changed, 15 insertions(+), 16 deletions(-) create mode 100644 src/main.h diff --git a/Makefile b/Makefile index 29d7bb4..5baff72 100644 --- a/Makefile +++ b/Makefile @@ -2,4 +2,4 @@ CC?=gcc BIN?=bin/elem make: src/main.c - $(CC) -o $(BIN) src/map.c src/loader.c src/command.c src/main.c \ No newline at end of file + $(CC) -ffunction-sections -fdata-sections -Wl,--gc-sections -Os -o $(BIN) src/map.c src/loader.c src/command.c src/main.c \ No newline at end of file diff --git a/src/command.c b/src/command.c index 321dc7a..0392267 100644 --- a/src/command.c +++ b/src/command.c @@ -4,12 +4,7 @@ #include #include -#define MAX_BUF_LENGTH 1024 -#define MAX_COMBO_LENGTH 1024 -#define poll_file "polls.txt" -#define polls_lock_file "polls_lock.txt" -#define combo_file "combos.txt" -#define UPVOTE_IN 2 +#include "main.h" struct pager { int page; diff --git a/src/loader.c b/src/loader.c index 190d34a..1a3eba4 100644 --- a/src/loader.c +++ b/src/loader.c @@ -4,7 +4,7 @@ #include #include -#define MAX_FILE_SIZE 1024 * 16 +#include "main.h" int load_elements(hashmap *m, char *table, int use_inv) { FILE *fptr; diff --git a/src/main.c b/src/main.c index 7809deb..561a50e 100644 --- a/src/main.c +++ b/src/main.c @@ -6,14 +6,7 @@ #include #include -#define inv_file "inv.txt" -#define inv_base_file "inv_base.txt" -#define combo_file "combos.txt" -#define poll_file "polls.txt" -#define polls_lock_file "polls_lock.txt" - -#define MAX_BUF_LENGTH 1024 -#define MAX_COMBO_LENGTH 1024 +#include "main.h" void init_tables(hashmap *elements, hashmap *inv, hashmap *polls, int do_inv) { load_elements(elements, "../elem_data/" combo_file, 0); diff --git a/src/main.h b/src/main.h new file mode 100644 index 0000000..02691b9 --- /dev/null +++ b/src/main.h @@ -0,0 +1,11 @@ +#define inv_file "inv.txt" +#define inv_base_file "inv_base.txt" +#define combo_file "combos.txt" +#define poll_file "polls.txt" +#define polls_lock_file "polls_lock.txt" + +#define MAX_BUF_LENGTH 1024 +#define MAX_COMBO_LENGTH 1024 +#define UPVOTE_IN 2 +#define MAX_FILE_SIZE 1024 * 16 +long stoi(const char *s); \ No newline at end of file