From 2d1a13a8115fa20805d1c68af9c7413c59066525 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 30 Aug 2016 07:51:05 +0100 Subject: [PATCH] death to static caches! --- src/kernel/item.c | 6 ++---- src/kernel/unit.c | 13 +++++-------- src/upkeep.c | 27 ++++++++++++++------------- src/util/rand.c | 2 +- src/util/umlaut.c | 2 +- 5 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/kernel/item.c b/src/kernel/item.c index 9816258c2..95d7461aa 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -862,11 +862,9 @@ struct order *ord) else { const race *irace = u_irace(u); if (irace == u_race(u)) { - static const race *rcfailure; + const race *rcfailure = rc_find("smurf"); if (!rcfailure) { - rcfailure = rc_find("smurf"); - if (!rcfailure) - rcfailure = rc_find("toad"); + rcfailure = rc_find("toad"); } if (rcfailure) { trigger *trestore = trigger_changerace(u, u_race(u), irace); diff --git a/src/kernel/unit.c b/src/kernel/unit.c index bb519e898..ba58849e6 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1389,15 +1389,12 @@ void default_name(const unit *u, char name[], int len) { const char * result; const struct locale * lang = u->faction ? u->faction->locale : default_locale; if (lang) { - static const char * prefix[MAXLOCALES]; - int i = locale_index(lang); - /*if (!prefix[i]) {*/ - prefix[i] = LOC(lang, "unitdefault"); - if (!prefix[i]) { - prefix[i] = parameters[P_UNIT]; + const char * prefix; + prefix = LOC(lang, "unitdefault"); + if (!prefix) { + prefix= parameters[P_UNIT]; } - /*}*/ - result = prefix[i]; + result = prefix; } else { result = parameters[P_UNIT]; diff --git a/src/upkeep.c b/src/upkeep.c index 5d114c74e..a9feca37a 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -58,27 +58,28 @@ static void help_feed(unit * donor, unit * u, int *need_p) *need_p = need; } +static const char *hunger_damage(const race *rc) { + const char * damage = get_param(rc->parameters, "hunger.damage"); + if (!damage) { + damage = config_get("hunger.damage"); + } + if (!damage) { + damage = "1d12+12"; + } + return damage; +} + static bool hunger(int number, unit * u) { region *r = u->region; int dead = 0, hpsub = 0; int hp = u->hp / u->number; - static const char *damage = 0; - static const char *rcdamage = 0; - static const race *rc = 0; + const char *damage = 0; - if (!damage) { - damage = config_get("hunger.damage"); - if (damage == NULL) - damage = "1d12+12"; - } - if (rc != u_race(u)) { - rcdamage = get_param(u_race(u)->parameters, "hunger.damage"); - rc = u_race(u); - } + damage = hunger_damage(u_race(u)); while (number--) { - int dam = dice_rand(rcdamage ? rcdamage : damage); + int dam = dice_rand(damage); if (dam >= hp) { ++dead; } diff --git a/src/util/rand.c b/src/util/rand.c index 1825340fe..73879656c 100644 --- a/src/util/rand.c +++ b/src/util/rand.c @@ -33,7 +33,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ double normalvariate(double mu, double sigma) { - static const double NV_MAGICCONST = 1.7155277699214135; /* STATIC_CONST: a constant */ + static const double NV_MAGICCONST = 1.7155277699214135; double z; for (;;) { double u1 = rng_double(); diff --git a/src/util/umlaut.c b/src/util/umlaut.c index 616596a01..9c37b852c 100644 --- a/src/util/umlaut.c +++ b/src/util/umlaut.c @@ -117,7 +117,7 @@ char * transliterate(char * out, size_t size, const char * in) void addtoken(void ** root, const char *str, variant id) { tnode * tk; - static const struct replace { /* STATIC_CONST: constant value */ + static const struct replace { ucs4_t ucs; const char str[3]; } replace[] = {