aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2025-12-08 04:12:03 -0500
committerB. Watson <urchlay@slackware.uk>2025-12-08 04:12:03 -0500
commitaa9cabfb0cd8b54a6bb920feb7bd296e339a6675 (patch)
tree4eea38054fd78d4fcb515e004c36c52f9698f867
parent586e6f177a32ead71b1f96a88c39d1a9d948aca6 (diff)
downloadalftools-aa9cabfb0cd8b54a6bb920feb7bd296e339a6675.tar.gz
crunch.c: stop using dynamic memory.
-rw-r--r--src/alf.16
-rw-r--r--src/alf.rst4
-rw-r--r--src/crunch.c29
3 files changed, 13 insertions, 26 deletions
diff --git a/src/alf.1 b/src/alf.1
index e06c44a..ac8cadd 100644
--- a/src/alf.1
+++ b/src/alf.1
@@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
-.TH "ALF" 1 "2025-12-07" "0.4.0" "Urchlay's Atari 8-bit Tools"
+.TH "ALF" 1 "2025-12-08" "0.4.0" "Urchlay's Atari 8-bit Tools"
.SH NAME
alf \- create Atari 8-bit ALF archives
.\" RST source for alf(1) man page. Convert with:
@@ -245,8 +245,8 @@ a DOS capable of handling multi\-megabyte files...
.sp
Performance is pretty good, as of alftools\-0.3.0. For small files
like you\(aqd use on an Atari (up to 50KB), it\(aqs basically instantaneous
-(0.009 seconds) on the author\(aqs modest i7 workstation. For a 1MB
-text file, it takes 0.046 sec; for 1MB of random garbage, it\(aqs 0.087
+(0.008 seconds) on the author\(aqs modest i7 workstation. For a 1MB
+text file, it takes 0.037 sec; for 1MB of random garbage, it\(aqs 0.062
sec (and the resulting ALF file is 36% larger than the garbage).
.sp
By comparison, \fBzip\fP takes 0.06 seconds to compress the 1MB text file,
diff --git a/src/alf.rst b/src/alf.rst
index 4bc4c7d..0756d95 100644
--- a/src/alf.rst
+++ b/src/alf.rst
@@ -218,8 +218,8 @@ Performance
Performance is pretty good, as of alftools-0.3.0. For small files
like you'd use on an Atari (up to 50KB), it's basically instantaneous
-(0.009 seconds) on the author's modest i7 workstation. For a 1MB
-text file, it takes 0.046 sec; for 1MB of random garbage, it's 0.087
+(0.008 seconds) on the author's modest i7 workstation. For a 1MB
+text file, it takes 0.037 sec; for 1MB of random garbage, it's 0.062
sec (and the resulting ALF file is 36% larger than the garbage).
By comparison, **zip** takes 0.06 seconds to compress the 1MB text file,
diff --git a/src/crunch.c b/src/crunch.c
index 315469b..3ab8eff 100644
--- a/src/crunch.c
+++ b/src/crunch.c
@@ -30,10 +30,7 @@ typedef struct s_token {
struct s_token *kids;
} token_t;
-token_t root_tokens[256];
-
-/* not used for lookups, just a fast way to free() everything */
-token_t *tokentab[MAX_TOKENS];
+token_t tokens[MAX_TOKENS];
int token_bits;
int max_token;
@@ -44,12 +41,9 @@ int new_pos;
void init_table(void) {
int i;
- for(i = INIT_TOKEN; i < curr_token; i++)
- free(tokentab[i]);
-
for(i = 0; i < 256; i++) {
- root_tokens[i].chr = root_tokens[i].number = i;
- root_tokens[i].kids = root_tokens[i].sibling = 0;
+ tokens[i].chr = tokens[i].number = i;
+ tokens[i].kids = tokens[i].sibling = 0;
}
token_bits = INITIAL_BITS;
@@ -106,9 +100,9 @@ void dump_tokens(void) {
maxkidcount = maxlevel = totalkidcount = nodeswithkids = 0;
for(i = 0; i < 256; i++) {
- if(root_tokens[i].kids) {
- printf("root_tokens[%s], #%d\n", fmt_chr(root_tokens[i].chr), root_tokens[i].number);
- dump_kids(&root_tokens[i], 1);
+ if(tokens[i].kids) {
+ printf("tokens[%s], #%d\n", fmt_chr(tokens[i].chr), tokens[i].number);
+ dump_kids(&tokens[i], 1);
}
}
@@ -162,7 +156,7 @@ token_t *get_kid(token_t *t, u8 chr) {
token_t *match_token(int pos) {
token_t *t, *p;
- t = &root_tokens[input_buf[pos]];
+ t = &tokens[input_buf[pos]];
new_pos = pos + 1;
if(new_pos == input_len)
return t;
@@ -179,18 +173,11 @@ token_t *match_token(int pos) {
token_t *new_token(u8 chr) {
token_t *newtok;
- newtok = malloc(sizeof(token_t));
- if(!newtok) {
- fprintf(stderr, "%s: fatal: out of memory!\n", self);
- exit(1);
- }
-
+ newtok = &tokens[curr_token];
newtok->chr = chr;
newtok->kids = newtok->sibling = 0;
newtok->number = curr_token;
- tokentab[curr_token] = newtok;
-
return newtok;
}