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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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)

View File

@@ -131,7 +131,7 @@ int nrect;
reg->n_monst = 0;
reg->max_monst = 0;
reg->monsters = (unsigned int *)0;
zero_anything(&reg->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(&reg->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);

View File

@@ -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));