optimization on memory

This commit is contained in:
biglyderv 2025-03-27 15:56:47 -04:00
parent 0e3dd1a83f
commit fe1de151ff
Signed by: biglyderv
GPG key ID: 0E2EB0B4CD7397B5
4 changed files with 14 additions and 5 deletions

View file

@ -111,6 +111,11 @@ int suggest_command(char *command, char *command_re, hashmap *polls,
}
page[strlen(page) - 1] = '\0';
if (strstr(page,"\n") || strstr(page,";") || strstr(page,",") || strstr(page,"+")) {
printf("This element contains illegal characters.\n");
return 1;
}
char *val = calloc(MAX_BUF_LENGTH, sizeof(char));
sprintf(val, "%s;%s", page, command_re);

View file

@ -32,12 +32,15 @@ int load_elements(hashmap *m, char *table, int use_inv) {
continue;
}
char *combo = strstr(str, ";");
combo[0] = '\0';
combo++;
char *combo_o = strstr(str, ";");
combo_o[0] = '\0';
combo_o++;
char *combo = calloc(strlen(combo_o)+1,sizeof(char));
strcpy(combo,combo_o);
if (use_inv == 2) {
hashmap_set(m, str, strlen(str) - 1, (uintptr_t)combo, 0);
hashmap_set(m, str, strlen(str) - 1, (uintptr_t)combo, 1);
continue;
}

View file

@ -25,6 +25,7 @@ void init_tables(hashmap *elements, hashmap *inv, hashmap *polls, int do_inv) {
load_elements(inv, inv_file, 1);
}
// todo: sanitize, valgrind, look through todos
int main(int argc, char *argv[]) {
char *name;
if (argc < 2) {

View file

@ -7,5 +7,5 @@
#define MAX_BUF_LENGTH 1024
#define MAX_COMBO_LENGTH 1024
#define UPVOTE_IN 2
#define MAX_FILE_SIZE 1024 * 16
#define MAX_FILE_SIZE 1024
long stoi(const char *s);