zeroany [trunk only]

Avoid function call when clearing 'anything' union.
This commit is contained in:
nethack.allison
2006-07-09 16:25:39 +00:00
parent 98a09101b1
commit 003aea0ce3
6 changed files with 16 additions and 15 deletions
+1
View File
@@ -250,6 +250,7 @@ E NEARDATA struct obj *uball;
E NEARDATA struct obj *migrating_objs; E NEARDATA struct obj *migrating_objs;
E NEARDATA struct obj *billobjs; E NEARDATA struct obj *billobjs;
E NEARDATA struct obj zeroobj; /* init'd and defined in decl.c */ 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" #include "you.h"
E NEARDATA struct you u; E NEARDATA struct you u;
+2
View File
@@ -194,6 +194,8 @@ NEARDATA struct obj *billobjs = (struct obj *)0;
/* used to zero all elements of a struct obj */ /* used to zero all elements of a struct obj */
NEARDATA struct obj zeroobj = DUMMY; NEARDATA struct obj zeroobj = DUMMY;
/* used to zero out union any*/
NEARDATA anything zeroany = DUMMY;
/* originally from dog.c */ /* originally from dog.c */
NEARDATA char dogname[PL_PSIZ] = DUMMY; NEARDATA char dogname[PL_PSIZ] = DUMMY;
+4 -4
View File
@@ -25,7 +25,7 @@ anything *
uint_to_any(ui) uint_to_any(ui)
unsigned ui; unsigned ui;
{ {
zero_anything(&tmp_anything); tmp_anything = zeroany;
tmp_anything.a_uint = ui; tmp_anything.a_uint = ui;
return &tmp_anything; return &tmp_anything;
} }
@@ -34,7 +34,7 @@ anything *
long_to_any(lng) long_to_any(lng)
unsigned lng; unsigned lng;
{ {
zero_anything(&tmp_anything); tmp_anything = zeroany;
tmp_anything.a_long = lng; tmp_anything.a_long = lng;
return &tmp_anything; return &tmp_anything;
} }
@@ -43,7 +43,7 @@ anything *
monst_to_any(mtmp) monst_to_any(mtmp)
struct monst *mtmp; struct monst *mtmp;
{ {
zero_anything(&tmp_anything); tmp_anything = zeroany;
tmp_anything.a_monst = mtmp; tmp_anything.a_monst = mtmp;
return &tmp_anything; return &tmp_anything;
} }
@@ -52,7 +52,7 @@ anything *
obj_to_any(obj) obj_to_any(obj)
struct obj *obj; struct obj *obj;
{ {
zero_anything(&tmp_anything); tmp_anything = zeroany;
tmp_anything.a_obj = obj; tmp_anything.a_obj = obj;
return &tmp_anything; return &tmp_anything;
} }
+3 -4
View File
@@ -92,8 +92,7 @@ del_light_source(type, id)
light_source *curr, *prev; light_source *curr, *prev;
anything tmp_id; anything tmp_id;
zero_anything(&tmp_id); tmp_id = zeroany;
/* need to be prepared for dealing a with light source which /* need to be prepared for dealing a with light source which
has only been partially restored during a level change has only been partially restored during a level change
(in particular: chameleon vs prot. from shape changers) */ (in particular: chameleon vs prot. from shape changers) */
@@ -390,7 +389,7 @@ write_ls(fd, ls)
arg_save = ls->id; arg_save = ls->id;
if (ls->type == LS_OBJECT) { if (ls->type == LS_OBJECT) {
otmp = ls->id.a_obj; otmp = ls->id.a_obj;
zero_anything(&ls->id); ls->id = zeroany;
ls->id.a_uint = otmp->o_id; ls->id.a_uint = otmp->o_id;
#ifdef DEBUG #ifdef DEBUG
if (find_oid((unsigned)ls->id) != otmp) if (find_oid((unsigned)ls->id) != otmp)
@@ -398,7 +397,7 @@ write_ls(fd, ls)
#endif #endif
} else { /* ls->type == LS_MONSTER */ } else { /* ls->type == LS_MONSTER */
mtmp = (struct monst *)ls->id.a_monst; mtmp = (struct monst *)ls->id.a_monst;
zero_anything(&ls->id); ls->id = zeroany;
ls->id.a_uint = mtmp->m_id; ls->id.a_uint = mtmp->m_id;
#ifdef DEBUG #ifdef DEBUG
if (find_mid((unsigned)ls->id, FM_EVERYWHERE) != mtmp) if (find_mid((unsigned)ls->id, FM_EVERYWHERE) != mtmp)
+3 -3
View File
@@ -131,7 +131,7 @@ int nrect;
reg->n_monst = 0; reg->n_monst = 0;
reg->max_monst = 0; reg->max_monst = 0;
reg->monsters = (unsigned int *)0; reg->monsters = (unsigned int *)0;
zero_anything(&reg->arg); reg->arg = zeroany;
return reg; return reg;
} }
@@ -901,7 +901,7 @@ genericptr_t p2; /* unused here */
/* If it was a thick cloud, it dissipates a little first */ /* If it was a thick cloud, it dissipates a little first */
if (damage >= 5) { if (damage >= 5) {
damage /= 2; /* It dissipates, let's do less damage */ damage /= 2; /* It dissipates, let's do less damage */
zero_anything(&reg->arg); reg->arg = zeroany;
reg->arg.a_int = damage; reg->arg.a_int = damage;
reg->ttl = 2L; /* Here's the trick : reset ttl */ reg->ttl = 2L; /* Here's the trick : reset ttl */
return FALSE; /* THEN return FALSE, means "still there" */ return FALSE; /* THEN return FALSE, means "still there" */
@@ -995,7 +995,7 @@ int damage;
set_heros_fault(cloud); /* assume player has created it */ set_heros_fault(cloud); /* assume player has created it */
cloud->inside_f = INSIDE_GAS_CLOUD; cloud->inside_f = INSIDE_GAS_CLOUD;
cloud->expire_f = EXPIRE_GAS_CLOUD; cloud->expire_f = EXPIRE_GAS_CLOUD;
zero_anything(&cloud->arg); cloud->arg = zeroany;
cloud->arg.a_int = damage; cloud->arg.a_int = damage;
cloud->visible = TRUE; cloud->visible = TRUE;
cloud->glyph = cmap_to_glyph(S_cloud); cloud->glyph = cmap_to_glyph(S_cloud);
+3 -4
View File
@@ -1723,8 +1723,7 @@ write_timer(fd, timer)
{ {
anything arg_save; anything arg_save;
zero_anything(&arg_save); arg_save = zeroany;
switch (timer->kind) { switch (timer->kind) {
case TIMER_GLOBAL: case TIMER_GLOBAL:
case TIMER_LEVEL: case TIMER_LEVEL:
@@ -1738,7 +1737,7 @@ write_timer(fd, timer)
else { else {
/* replace object pointer with id */ /* replace object pointer with id */
arg_save.a_obj = timer->arg.a_obj; 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->arg.a_uint = (arg_save.a_obj)->o_id;
timer->needs_fixup = 1; timer->needs_fixup = 1;
bwrite(fd, (genericptr_t)timer, sizeof(timer_element)); bwrite(fd, (genericptr_t)timer, sizeof(timer_element));
@@ -1753,7 +1752,7 @@ write_timer(fd, timer)
else { else {
/* replace monster pointer with id */ /* replace monster pointer with id */
arg_save.a_monst = timer->arg.a_monst; 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->arg.a_uint = (arg_save.a_monst)->m_id;
timer->needs_fixup = 1; timer->needs_fixup = 1;
bwrite(fd, (genericptr_t)timer, sizeof(timer_element)); bwrite(fd, (genericptr_t)timer, sizeof(timer_element));