Commit: 456424d3a112817b3a365479a6ff346676136311
Parent: bb10073291b1d339be9be2e46cfe5d3ae2aa9178
Author: Randy Palamar
Date: Tue, 7 Mar 2023 12:53:46 -0700
charsets.c: don't duplicate static global strs just store the ptr
Diffstat:
3 files changed, 5 insertions(+), 43 deletions(-)
diff --git a/charsets.c b/charsets.c
@@ -110,48 +110,19 @@ encode_utf_8(int u)
return utf_buffer;
}
-static struct conv_table utf_table[256];
-static int utf_table_init = 1;
-
-static void
-free_utf_table(void)
-{
- int i;
- for (i = 128; i < 256; i += 4) {
- free(utf_table[i].u.str);
- free(utf_table[i + 1].u.str);
- free(utf_table[i + 2].u.str);
- free(utf_table[i + 3].u.str);
- }
-}
-
static struct conv_table *
get_translation_table_to_utf_8(int from)
{
+ static struct conv_table utf_table[256];
+ static int init = 0, lfr = -1;
int i;
- static int lfr = -1;
if (from == lfr)
return utf_table;
lfr = from;
- if (utf_table_init) {
- memset(utf_table, 0, sizeof(struct conv_table) * 256);
- for (i = 0; i < 128; i += 4) {
+ if (!init) {
+ for (i = 0; i < 256; i++)
utf_table[i].u.str = (unsigned char *)strings[i];
- utf_table[i + 1].u.str =
- (unsigned char *)strings[i + 1];
- utf_table[i + 2].u.str =
- (unsigned char *)strings[i + 2];
- utf_table[i + 3].u.str =
- (unsigned char *)strings[i + 3];
- }
- utf_table_init = 0;
- } else
- free_utf_table();
- for (i = 128; i < 256; i += 4) {
- utf_table[i].u.str = stracpy(strings[i]);
- utf_table[i + 1].u.str = stracpy(strings[i + 1]);
- utf_table[i + 2].u.str = stracpy(strings[i + 2]);
- utf_table[i + 3].u.str = stracpy(strings[i + 3]);
+ init = 1;
}
return utf_table;
}
@@ -199,13 +170,6 @@ get_utf_8(unsigned char **s)
return v;
}
-void
-free_conv_table(void)
-{
- if (!utf_table_init)
- free_utf_table();
-}
-
struct conv_table *
get_translation_table(const int from, const int to)
{
diff --git a/links.h b/links.h
@@ -2068,7 +2068,6 @@ unsigned char *convert(int from, int to, unsigned char *c,
struct document_options *dopt);
unsigned char *get_cp_name(int);
unsigned char *get_cp_mime_name(int);
-void free_conv_table(void);
unsigned char *encode_utf_8(int);
unsigned char *u2cp(int u);
diff --git a/main.c b/main.c
@@ -396,7 +396,6 @@ terminate_all_subsystems(void)
free_term_specs();
free_types();
finalize_bookmarks();
- free_conv_table();
free_blacklist();
free_cookies();
free_auth();