From: nethack.allison Date: Sun, 9 Jul 2006 16:25:39 +0000 (+0000) Subject: zeroany [trunk only] X-Git-Tag: MOVE2GIT~952 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=003aea0ce3707c444a5bcee88c186ffd6b81bc5e;p=nethack zeroany [trunk only] Avoid function call when clearing 'anything' union. --- diff --git a/include/decl.h b/include/decl.h index 984d3f097..511e67c2b 100644 --- a/include/decl.h +++ b/include/decl.h @@ -250,6 +250,7 @@ E NEARDATA struct obj *uball; E NEARDATA struct obj *migrating_objs; E NEARDATA struct obj *billobjs; E NEARDATA struct obj zeroobj; /* init'd and defined in decl.c */ +E NEARDATA anything zeroany; /* init'd and defined in decl.c */ #include "you.h" E NEARDATA struct you u; diff --git a/src/decl.c b/src/decl.c index 8d1fbfbec..4640d3534 100644 --- a/src/decl.c +++ b/src/decl.c @@ -194,6 +194,8 @@ NEARDATA struct obj *billobjs = (struct obj *)0; /* used to zero all elements of a struct obj */ NEARDATA struct obj zeroobj = DUMMY; +/* used to zero out union any*/ +NEARDATA anything zeroany = DUMMY; /* originally from dog.c */ NEARDATA char dogname[PL_PSIZ] = DUMMY; diff --git a/src/hack.c b/src/hack.c index 2d2474847..df33a4e84 100644 --- a/src/hack.c +++ b/src/hack.c @@ -25,7 +25,7 @@ anything * uint_to_any(ui) unsigned ui; { - zero_anything(&tmp_anything); + tmp_anything = zeroany; tmp_anything.a_uint = ui; return &tmp_anything; } @@ -34,7 +34,7 @@ anything * long_to_any(lng) unsigned lng; { - zero_anything(&tmp_anything); + tmp_anything = zeroany; tmp_anything.a_long = lng; return &tmp_anything; } @@ -43,7 +43,7 @@ anything * monst_to_any(mtmp) struct monst *mtmp; { - zero_anything(&tmp_anything); + tmp_anything = zeroany; tmp_anything.a_monst = mtmp; return &tmp_anything; } @@ -52,7 +52,7 @@ anything * obj_to_any(obj) struct obj *obj; { - zero_anything(&tmp_anything); + tmp_anything = zeroany; tmp_anything.a_obj = obj; return &tmp_anything; } diff --git a/src/light.c b/src/light.c index 2770ed209..1940a8434 100644 --- a/src/light.c +++ b/src/light.c @@ -92,8 +92,7 @@ del_light_source(type, id) light_source *curr, *prev; anything tmp_id; - zero_anything(&tmp_id); - + tmp_id = zeroany; /* need to be prepared for dealing a with light source which has only been partially restored during a level change (in particular: chameleon vs prot. from shape changers) */ @@ -390,7 +389,7 @@ write_ls(fd, ls) arg_save = ls->id; if (ls->type == LS_OBJECT) { otmp = ls->id.a_obj; - zero_anything(&ls->id); + ls->id = zeroany; ls->id.a_uint = otmp->o_id; #ifdef DEBUG if (find_oid((unsigned)ls->id) != otmp) @@ -398,7 +397,7 @@ write_ls(fd, ls) #endif } else { /* ls->type == LS_MONSTER */ mtmp = (struct monst *)ls->id.a_monst; - zero_anything(&ls->id); + ls->id = zeroany; ls->id.a_uint = mtmp->m_id; #ifdef DEBUG if (find_mid((unsigned)ls->id, FM_EVERYWHERE) != mtmp) diff --git a/src/region.c b/src/region.c index b719cdce4..4aa3761ab 100644 --- a/src/region.c +++ b/src/region.c @@ -131,7 +131,7 @@ int nrect; reg->n_monst = 0; reg->max_monst = 0; reg->monsters = (unsigned int *)0; - zero_anything(®->arg); + reg->arg = zeroany; return reg; } @@ -901,7 +901,7 @@ genericptr_t p2; /* unused here */ /* If it was a thick cloud, it dissipates a little first */ if (damage >= 5) { damage /= 2; /* It dissipates, let's do less damage */ - zero_anything(®->arg); + reg->arg = zeroany; reg->arg.a_int = damage; reg->ttl = 2L; /* Here's the trick : reset ttl */ return FALSE; /* THEN return FALSE, means "still there" */ @@ -995,7 +995,7 @@ int damage; set_heros_fault(cloud); /* assume player has created it */ cloud->inside_f = INSIDE_GAS_CLOUD; cloud->expire_f = EXPIRE_GAS_CLOUD; - zero_anything(&cloud->arg); + cloud->arg = zeroany; cloud->arg.a_int = damage; cloud->visible = TRUE; cloud->glyph = cmap_to_glyph(S_cloud); diff --git a/src/timeout.c b/src/timeout.c index beb5c3764..70d321537 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -1723,8 +1723,7 @@ write_timer(fd, timer) { anything arg_save; - zero_anything(&arg_save); - + arg_save = zeroany; switch (timer->kind) { case TIMER_GLOBAL: case TIMER_LEVEL: @@ -1738,7 +1737,7 @@ write_timer(fd, timer) else { /* replace object pointer with id */ arg_save.a_obj = timer->arg.a_obj; - zero_anything(&timer->arg); + timer->arg = zeroany; timer->arg.a_uint = (arg_save.a_obj)->o_id; timer->needs_fixup = 1; bwrite(fd, (genericptr_t)timer, sizeof(timer_element)); @@ -1753,7 +1752,7 @@ write_timer(fd, timer) else { /* replace monster pointer with id */ arg_save.a_monst = timer->arg.a_monst; - zero_anything(&timer->arg); + timer->arg = zeroany; timer->arg.a_uint = (arg_save.a_monst)->m_id; timer->needs_fixup = 1; bwrite(fd, (genericptr_t)timer, sizeof(timer_element));