From 8ff26eb0e4ba755a2033625a2f879608eac47d85 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 29 Aug 2016 19:41:21 +0100 Subject: [PATCH] optimization: no need to look for a curse if unit has no attribs. --- src/move.c | 19 ++++++++----------- src/reports.c | 16 ++++++++-------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/move.c b/src/move.c index 156c3c5d2..3cc93855d 100644 --- a/src/move.c +++ b/src/move.c @@ -1463,8 +1463,6 @@ static void make_route(unit * u, order * ord, region_list ** routep) static int movement_speed(unit * u) { int mp = BP_WALKING; - static const curse_type *speed_ct; - static bool init = false; double dk = u_race(u)->speed; assert(u->number); @@ -1482,15 +1480,14 @@ static int movement_speed(unit * u) break; } - if (!init) { - init = true; - speed_ct = ct_find("speed"); - } - if (speed_ct) { - curse *c = get_curse(u->attribs, speed_ct); - if (c != NULL) { - int men = get_cursedmen(u, c); - dk *= 1.0 + (double)men / (double)u->number; + if (u->attribs) { + const curse_type *speed_ct = ct_find("speed"); + if (speed_ct) { + curse *c = get_curse(u->attribs, speed_ct); + if (c != NULL) { + int men = get_cursedmen(u, c); + dk *= 1.0 + (double)men / (double)u->number; + } } } diff --git a/src/reports.c b/src/reports.c index 7173bcf3f..679b1be42 100644 --- a/src/reports.c +++ b/src/reports.c @@ -270,18 +270,18 @@ report_items(const unit *u, item * result, int size, const unit * owner, { const item *itm, *items = u->items; int n = 0; /* number of results */ - bool itemcloak = false; - const curse_type *itemcloak_ct = ct_find("itemcloak"); assert(owner == NULL || viewer != owner->faction); assert(size); - if (itemcloak_ct) { - curse * cu = get_curse(u->attribs, itemcloak_ct); - itemcloak = cu && curse_active(cu); - } - if (itemcloak) { - return 0; + if (u->attribs) { + const curse_type *itemcloak_ct = ct_find("itemcloak"); + if (itemcloak_ct) { + curse * cu = get_curse(u->attribs, itemcloak_ct); + if (cu && curse_active(cu)) { + return 0; + } + } } for (itm = items; itm; itm = itm->next) { item *ishow;