From b9b2b75f73ee8bb9ab361d22d3ba3579185cdfea Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Sat, 27 Dec 2008 05:32:36 +0000 Subject: [PATCH] Drop zero-initialisation of static storage In get_entity_string and point_intersect, do not initialise arrays with static storage duration to zero; the C standard states that such objects are automatically initialised to zero. --- src/intl/charsets.c | 9 +++------ src/viewer/text/search.c | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/intl/charsets.c b/src/intl/charsets.c index 4170ec3e1..23442fbfb 100644 --- a/src/intl/charsets.c +++ b/src/intl/charsets.c @@ -1067,10 +1067,12 @@ get_entity_string(const unsigned char *str, const int strlen, int encoding) will go in [0] table */ static struct entity_cache entity_cache[ENTITY_CACHE_MAXLEN][ENTITY_CACHE_SIZE]; static unsigned int nb_entity_cache[ENTITY_CACHE_MAXLEN]; - static int first_time = 1; unsigned int slen = 0; const unsigned char *result = NULL; + /* Note that an object of static storage duration is automatically + * initialised to zero in C. */ + if (strlen <= 0) return NULL; #ifdef CONFIG_UTF8 @@ -1080,11 +1082,6 @@ get_entity_string(const unsigned char *str, const int strlen, int encoding) goto skip; #endif /* CONFIG_UTF8 */ - if (first_time) { - memset(&nb_entity_cache, 0, ENTITY_CACHE_MAXLEN * sizeof(unsigned int)); - first_time = 0; - } - /* Check if cached. A test on many websites (freshmeat.net + whole ELinks website * + google + slashdot + websites that result from a search for test on google, * + various ones) show quite impressive improvment: diff --git a/src/viewer/text/search.c b/src/viewer/text/search.c index e34540480..f921f8786 100644 --- a/src/viewer/text/search.c +++ b/src/viewer/text/search.c @@ -889,16 +889,13 @@ point_intersect(struct point *p1, int l1, struct point *p2, int l2) int i; static char hash[HASH_SIZE]; - static int first_time = 1; + + /* Note that an object of static storage duration is automatically + * initialised to zero in C. */ assert(p2); if_assert_failed return 0; - if (first_time) { - memset(hash, 0, HASH_SIZE); - first_time = 0; - } - for (i = 0; i < l1; i++) hash[HASH(p1[i])] = 1; for (i = 0; i < l2; i++) {