Skip to content

Commit

Permalink
more efficient global bools
Browse files Browse the repository at this point in the history
STOBOOL is inefficient since it contains 2 branches, and 2 layers
of indirection (read the global var containing a ptr, read 1st byte at
that ptr) and a NULL test. Removing the NULL test will make dmake crash
if a makefile does "OOODMAKEMODE = \n" which will set the global char *
to NULL, since Def_macro() changes "" to NULL.

M_VAR_CHAR is totally unused by dmake, and the only bit we can reuse in
highest nibble of M_* flags. This way all the M_VAR flags remain in the
same nibble. A bit_var is not a "STOBOOL" style bool. A bit_var is
interpreted as ""/NULL being false, everything
else is true, "n" is true for example with a bit_var but false with
STOBOOL style bools.

Reuse M_VAR_CHAR to make a more efficiency bool type for dmake.
  • Loading branch information
bulk88 authored and mohawk2 committed Mar 9, 2015
1 parent 31ecafb commit 4558fae
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 23 deletions.
7 changes: 5 additions & 2 deletions dag.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ HASHPTR hp;
/* No special treatment for TMD needed. */
break;

case M_VAR_CHAR:
*hp->MV_CVAR = (hp->ht_value == NIL(char)) ? '\0':*hp->ht_value;
case M_VAR_BOOL:
*hp->MV_CVAR = (hp->ht_value == NIL(char)) ? FALSE:
/* |0x20 turns turn ASCII 'Y' into 'y', if 'y' it stays as 'y' */
(*hp->ht_value | 0x20)== 'y'
? TRUE : FALSE;
break;

case M_VAR_INT: {
Expand Down
3 changes: 2 additions & 1 deletion dmake.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
* an empty macro implicitly
* defined when expanding it. */
#define M_VAR_BIT 0x1000 /* macro bit variable */
#define M_VAR_CHAR 0x2000 /* macro char variable */
#define M_VAR_BOOL 0x2000 /* macro bool variable */
#define M_VAR_STRING 0x4000 /* macro string variable */
#define M_VAR_INT 0x8000 /* macro integer variable */

Expand Down Expand Up @@ -226,6 +226,7 @@
#define GET_MACRO(A) Get_name(A, Macs, FALSE)
#define iswhite(C) ((C == ' ') || (C == '\t'))
#define STOBOOL(A) (A && ((*A | 0x20) == 'y'))
#define BTOBOOL(A) (A)

#endif

41 changes: 35 additions & 6 deletions imacs.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

static void _set_int_var ANSI((char *, char *, int, int *));
static void _set_int_var_from_int_and_str ANSI((char *, int, char *, int, int *));
static void _set_bool_var ANSI((char *, int, int, char *));
static void _set_string_var ANSI((char *, char *, int, char **));
static void _set_bit_var ANSI((char *, char *, int));

Expand Down Expand Up @@ -109,18 +110,19 @@ Create_macro_vars()
_set_string_var("GROUPFLAGS", " ", M_DEFAULT, &GShell_flags);
_set_string_var("SHELLMETAS", "", M_DEFAULT, &Shell_metas );
_set_string_var("GROUPSUFFIX", "", M_DEFAULT, &Grp_suff );
_set_string_var("AUGMAKE",NIL(char), M_DEFAULT, &Augmake );
_set_string_var("OOODMAKEMODE", "", M_DEFAULT, &OOoDmMode );
_set_bool_var ("AUGMAKE", FALSE,M_DEFAULT, &Augmake );
_set_bool_var ("OOODMAKEMODE",FALSE,M_DEFAULT, &OOoDmMode );
_set_string_var(".KEEP_STATE", "", M_DEFAULT, &Keep_state );
_set_string_var(".NOTABS", "", M_MULTI, &Notabs );
_set_string_var(".DIRCACHE", "y", M_DEFAULT, &UseDirCache );
_set_bool_var (".DIRCACHE", TRUE, M_DEFAULT, &UseDirCache );

#if CASE_INSENSITIVE_FS
#define DIRCACHERESPCASEDEFAULT ""
#define DIRCACHERESPCASEDEFAULT FALSE
#else
#define DIRCACHERESPCASEDEFAULT "y"
#define DIRCACHERESPCASEDEFAULT TRUE
#endif
_set_string_var(".DIRCACHERESPCASE", DIRCACHERESPCASEDEFAULT, M_DEFAULT, &DcacheRespCase);
_set_bool_var (".DIRCACHERESPCASE", DIRCACHERESPCASEDEFAULT, M_DEFAULT, &DcacheRespCase);
#undef DIRCACHERESPCASEDEFAULT

_set_string_var("MAKEDIR",Get_current_dir(),M_PRECIOUS|M_NOEXPORT,
&Makedir_macval);
Expand Down Expand Up @@ -195,6 +197,33 @@ int *var;
}


/*
** Define an bool variable, and set up the macro.
** Unlike _set_bit_var, this does not use global Glob_attr (Glob_attr's
** bits are all used up anyway), and a bool takes 'Y' or 'y' as true, every
** other string including NIL(char) are false, which is differnt from bit_var's
** conversions to true and false. A bool is a global char var. Glob_attr could
** be converted to a bit vector instead of being int32_t in the future but
** the string to bool/bit conversion still needs a flag on whether its a
** ""/NULL or 'y' conversion.
*/
static void
_set_bool_var(name, val, flag, var)
char *name;
int val;
int flag;
char *var;
{
HASHPTR hp;
char *valstr = val ? "y" : NIL(char);

hp = Def_macro(name, valstr, M_FLAG | flag);
hp->ht_flag |= M_VAR_BOOL | M_MULTI | M_INIT;
hp->MV_CVAR = var;
*var = val;
}


/*
** Define a string variables value, and set up the macro.
*/
Expand Down
2 changes: 1 addition & 1 deletion make.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ CELLPTR setdirroot;
goto stop_making_it;
}
else if( cp->ce_prq != NIL(LINK)
|| (STOBOOL(Augmake) && (cp->ce_flag&F_EXPLICIT)))
|| (BTOBOOL(Augmake) && (cp->ce_flag&F_EXPLICIT)))
/* Assume an empty recipe for a target that we have run inference on
* but do not have a set of rules for but for which we have inferred
* a list of prerequisites. */
Expand Down
2 changes: 1 addition & 1 deletion msdos/dstrlwr.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dstrlwr(entry, target)
char *entry;
char *target;
{
if (STOBOOL(DcacheRespCase))
if (BTOBOOL(DcacheRespCase))
return;

/* Look for the target being lower case, if so then lower the case
Expand Down
2 changes: 1 addition & 1 deletion path.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ char *path;

/* Remove './'. If OOODMAKEMODE is set do this only if it is not at
* the start of the path. */
if ( p-q == 1 && *q == '.' && (q != path || !STOBOOL(OOoDmMode)) ) {
if ( p-q == 1 && *q == '.' && (q != path || !BTOBOOL(OOoDmMode)) ) {
len = strlen(p+1)+1;
memmove(q,p+1,len);
q = tpath;
Expand Down
2 changes: 1 addition & 1 deletion rulparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ _build_meta( name )/*
char *name;
{
char *tmp;
int test = (STOBOOL(Augmake) ? name[strlen(name)-1] == '~' : 0);
int test = (BTOBOOL(Augmake) ? name[strlen(name)-1] == '~' : 0);

tmp = DmStrJoin( test ? "s.%" : "%", name, -1, FALSE);
if( test ) tmp[ strlen(tmp)-1 ] = '\0';
Expand Down
4 changes: 2 additions & 2 deletions sysintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ char *name;
DMPORTSTAT_T *buf;
{
return( ( !DMPORTSTAT_SUCCESS(DMPORTSTAT(name,buf))
|| (STOBOOL(Augmake) && DMPORTSTAT_ISDIR(buf)))
|| (BTOBOOL(Augmake) && DMPORTSTAT_ISDIR(buf)))
? (time_t)0L
: (time_t)DMPORTSTAT_MTIME(buf)
);
Expand Down Expand Up @@ -122,7 +122,7 @@ int force;
Assume unix time 0.\n", basename, NameMax );
return((time_t)0L);
}
else if( STOBOOL(UseDirCache) )
else if( BTOBOOL(UseDirCache) )
return(CacheStat(name,force));
else
return(really_dostat(name,&buf));
Expand Down
8 changes: 4 additions & 4 deletions unix/dcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ int force;
dir = Filedir(fpath);

/* do caching and comparing lower case if told so. */
if( !STOBOOL(DcacheRespCase) ) {
if( !BTOBOOL(DcacheRespCase) ) {
udir = DmStrDup(dir);
strlwr(comp);
strlwr(dir);
Expand Down Expand Up @@ -157,7 +157,7 @@ int force;
while((direntp=readdir(dirp)) != NULL) {
TALLOC(ep,1,Entry);
ep->name = DmStrDup(direntp->d_name); /* basename only */
if( !STOBOOL(DcacheRespCase) )
if( !BTOBOOL(DcacheRespCase) )
strlwr(ep->name);

Hash(ep->name, &ep->hkey); /* This sets ep->hkey. */
Expand Down Expand Up @@ -208,7 +208,7 @@ int force;
if (!ep) {
TALLOC(ep,1,Entry);
ep->name = DmStrDup(comp);
if( !STOBOOL(DcacheRespCase) ) {
if( !BTOBOOL(DcacheRespCase) ) {
strlwr(ep->name);
Hash(ep->name, &ep->hkey);
}
Expand All @@ -231,5 +231,5 @@ int force;
FREE(udir); /* Keep this before the free of fpath. */

FREE(fpath);
return(!ep ? (time_t)0L : ((STOBOOL(Augmake) && ep->isdir)?0L:ep->mtime));
return(!ep ? (time_t)0L : ((BTOBOOL(Augmake) && ep->isdir)?0L:ep->mtime));
}
8 changes: 4 additions & 4 deletions vextern.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ EXTERN char* Spacechar; /* pointer to macro value for SPACECHAR */
EXTERN char* Keep_state; /* current .KEEP_STATE file */
EXTERN char* Escape_char; /* Current escape character */
EXTERN char* LastMacName; /* Last macro successfully parsed */
EXTERN char* UseDirCache; /* The value of .DIRCACHE */
EXTERN char* DcacheRespCase; /* TRUE if we are to respect dcache case */
EXTERN char* OOoDmMode; /* Enable special behavior for OOo build. */
EXTERN char UseDirCache; /* The value of .DIRCACHE */
EXTERN char DcacheRespCase; /* TRUE if we are to respect dcache case */
EXTERN char OOoDmMode; /* Enable special behavior for OOo build. */
EXTERN int Target; /* TRUE if a default target was found in *
* a makefile or on the commandline */
EXTERN int If_expand; /* TRUE if calling Expand from getinp.c */
Expand Down Expand Up @@ -103,7 +103,7 @@ EXTERN int Group; /* parsing a group recipe ==> TRUE */
/* Command line option flags are defined here. They correspond one-for one
* with the flags defined in dmake.c */

EXTERN char *Augmake; /* -A */
EXTERN char Augmake; /* -A */
EXTERN char Comment; /* -c */
EXTERN char Get_env; /* -e or -E */
EXTERN char* Notabs; /* -B */
Expand Down

0 comments on commit 4558fae

Please sign in to comment.