From 9af5fb032674790449f42118d979ea7bae72c8c4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 19 Sep 2016 04:23:49 +0200 Subject: [PATCH] cache some of the highest-ranking ct_find callers --- src/kernel/config.c | 11 +++++++---- src/kernel/unit.c | 6 +++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index d78362f3c..5b51950e0 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -923,8 +923,12 @@ default_wage(const region * r, const faction * f, const race * rc, int in_turn) int esize = 0; double wage; attrib *a; - const struct curse_type *ctype; + static int ct_cache; + static const struct curse_type *drought_ct; + if (ct_changed(&ct_cache)) { + drought_ct = ct_find("drought"); + } if (b != NULL) { /* TODO: this reveals imaginary castles */ esize = buildingeffsize(b, false); @@ -969,9 +973,8 @@ default_wage(const region * r, const faction * f, const race * rc, int in_turn) } /* Bei einer Dürre verdient man nur noch ein Viertel */ - ctype = ct_find("drought"); - if (ctype) { - curse *c = get_curse(r->attribs, ctype); + if (drought_ct) { + curse *c = get_curse(r->attribs, drought_ct); if (curse_active(c)) wage /= curse_geteffect(c); } diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 08f9314f3..246f59cb7 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1733,7 +1733,11 @@ int unit_max_hp(const unit * u) /* der healing curse veraendert die maximalen hp */ if (u->region && u->region->attribs) { - const curse_type *heal_ct = ct_find("healingzone"); + static int cache; + static const curse_type *heal_ct; + if (ct_changed(&cache)) { + heal_ct = ct_find("healingzone"); + } if (heal_ct) { curse *c = get_curse(u->region->attribs, heal_ct); if (c) {