cast to bool optimization
This commit is contained in:
@@ -162,7 +162,8 @@ template <class T> inline int compare_two(T a, T b) { return a < b ? -1 : a
|
||||
template <class T> inline T minimum_of_two(T a, T b) { return (a < b) ? a : b; }
|
||||
template <class T> inline T maximum_of_two(T a, T b) { return (a > b) ? a : b; }
|
||||
template <class T> inline int zero_or_one(T e) { return e ? 1 : 0; }
|
||||
template <class T> inline bool make_bool(T a) { return a != 0; }
|
||||
template <class T> inline bool make_bool(T a) { return !!a; }
|
||||
template <class T> inline bool make_bool_not(T a) { return !a; }
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
|
@@ -96,7 +96,7 @@ int gfile::okay() {
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
int gfile::isopen() {
|
||||
bool gfile::isopen() {
|
||||
|
||||
if((fh != -1) or (fp != NULL))
|
||||
return true;
|
||||
|
@@ -64,7 +64,7 @@ public:
|
||||
// Handy utility functions
|
||||
|
||||
int okay(); // Returns non-zero if no errors were detected
|
||||
int isopen(); // true if the file is open
|
||||
bool isopen(); // true if the file is open
|
||||
|
||||
|
||||
// --------------------------------------------------------------
|
||||
@@ -78,7 +78,7 @@ public:
|
||||
|
||||
~gfile(); // Destructor (closes file)
|
||||
|
||||
operator bool() { return isopen() ? true : false; }
|
||||
operator bool() { return isopen(); }
|
||||
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
@@ -178,7 +178,7 @@ int is_dir(const char* path) {
|
||||
|
||||
struct stat st;
|
||||
if(stat(tmp, &st) == 0)
|
||||
return (st.st_mode & S_IFDIR) ? true : false;
|
||||
return make_bool(st.st_mode & S_IFDIR);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -182,7 +182,7 @@ bool gfuzzy::findnext() {
|
||||
}
|
||||
}
|
||||
|
||||
return start ? true : false;
|
||||
return make_bool(start);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -134,7 +134,7 @@ void GKbd::Init() {
|
||||
OSVERSIONINFO osversion;
|
||||
osversion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
GetVersionEx(&osversion);
|
||||
gkbd_nt = (osversion.dwPlatformId & VER_PLATFORM_WIN32_NT) ? true : false;
|
||||
gkbd_nt = make_bool(osversion.dwPlatformId & VER_PLATFORM_WIN32_NT);
|
||||
gkbd_hin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
||||
OPEN_EXISTING, 0, NULL);
|
||||
@@ -1283,9 +1283,9 @@ gkey kbxget_raw(int mode) {
|
||||
}
|
||||
|
||||
if((inp.EventType == KEY_EVENT) and inp.Event.KeyEvent.bKeyDown) {
|
||||
bool alt_pressed = (CKS & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) ? true : false;
|
||||
bool ctrl_pressed = (CKS & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED)) ? true : false;
|
||||
bool shift_pressed = (CKS & SHIFT_PRESSED) ? true : false;
|
||||
bool alt_pressed = make_bool(CKS & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED));
|
||||
bool ctrl_pressed = make_bool(CKS & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED));
|
||||
bool shift_pressed = make_bool(CKS & SHIFT_PRESSED);
|
||||
bool special_key = false;
|
||||
|
||||
k = 0;
|
||||
|
@@ -135,7 +135,7 @@ public:
|
||||
void HideCursor();
|
||||
void ShowCursor();
|
||||
|
||||
int Hidden() { return hidden ? true : false; }
|
||||
int Hidden() { return make_bool(hidden); }
|
||||
|
||||
int Enabled() { return level > GMOU_LEVEL_NONE; }
|
||||
|
||||
|
@@ -71,7 +71,7 @@ bool gregex::compile(const char* pattern, int cflags) {
|
||||
throw_new(preg);
|
||||
}
|
||||
|
||||
return regcomp(preg, pattern, cflgs) ? true : false;
|
||||
return make_bool(regcomp(preg, pattern, cflgs));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -474,7 +474,7 @@ int gsnd::is_playing() {
|
||||
#if defined(__MSDOS__)
|
||||
|
||||
if(file_open)
|
||||
return data->status == 0 ? false : true;
|
||||
return make_bool_not(data->status == 0);
|
||||
return false;
|
||||
|
||||
#elif defined(GUTLOS_FUNCS)
|
||||
|
@@ -57,19 +57,19 @@ extern mail_ctype mail_ctype_global;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
inline bool is_mail_char(uint c) { return (mail_ctype_global.table[c] & mail_ctype::mail_char) ? true : false; }
|
||||
inline bool is_mail_alpha(uint c) { return (mail_ctype_global.table[c] & mail_ctype::mail_alpha) ? true : false; }
|
||||
inline bool is_mail_ctl(uint c) { return (mail_ctype_global.table[c] & mail_ctype::mail_ctl) ? true : false; }
|
||||
inline bool is_mail_char(uint c) { return make_bool(mail_ctype_global.table[c] & mail_ctype::mail_char); }
|
||||
inline bool is_mail_alpha(uint c) { return make_bool(mail_ctype_global.table[c] & mail_ctype::mail_alpha); }
|
||||
inline bool is_mail_ctl(uint c) { return make_bool(mail_ctype_global.table[c] & mail_ctype::mail_ctl); }
|
||||
inline bool is_mail_cr(uint c) { return c == CR; }
|
||||
inline bool is_mail_lf(uint c) { return c == LF; }
|
||||
inline bool is_mail_space(uint c) { return c == ' '; }
|
||||
inline bool is_mail_htab(uint c) { return c == HT; }
|
||||
inline bool is_mail_crlf(uint c) { return is_mail_cr(c) or is_mail_lf(c); }
|
||||
inline bool is_mail_lwsp(uint c) { return (mail_ctype_global.table[c] & mail_ctype::mail_lwsp) ? true : false; }
|
||||
inline bool is_mail_special(uint c) { return (mail_ctype_global.table[c] & mail_ctype::mail_special) ? true : false; }
|
||||
inline bool is_mail_delimiters(uint c) { return (mail_ctype_global.table[c] & mail_ctype::mail_delimiters) ? true : false; }
|
||||
inline bool is_mime_tspecial(uint c) { return (mail_ctype_global.table[c] & mail_ctype::mime_tspecial) ? true : false; }
|
||||
inline bool is_mime_especial(uint c) { return (mail_ctype_global.table[c] & mail_ctype::mime_especial) ? true : false; }
|
||||
inline bool is_mail_lwsp(uint c) { return make_bool(mail_ctype_global.table[c] & mail_ctype::mail_lwsp); }
|
||||
inline bool is_mail_special(uint c) { return make_bool(mail_ctype_global.table[c] & mail_ctype::mail_special); }
|
||||
inline bool is_mail_delimiters(uint c) { return make_bool(mail_ctype_global.table[c] & mail_ctype::mail_delimiters); }
|
||||
inline bool is_mime_tspecial(uint c) { return make_bool(mail_ctype_global.table[c] & mail_ctype::mime_tspecial); }
|
||||
inline bool is_mime_especial(uint c) { return make_bool(mail_ctype_global.table[c] & mail_ctype::mime_especial); }
|
||||
inline bool is_mail_atom_delimiters(uint c) { return is_mail_delimiters(c) or is_mail_ctl(c); }
|
||||
inline bool is_mime_ct_token_valid(uint c) { return not (is_mail_lwsp(c) or is_mail_ctl(c) or is_mime_tspecial(c)); }
|
||||
|
||||
|
@@ -102,11 +102,11 @@ bool gclipbrd::writeclipbrd(const char* buf) {
|
||||
if(fake_clipboard)
|
||||
throw_free(fake_clipboard);
|
||||
fake_clipboard = throw_strdup(buf);
|
||||
return (fake_clipboard != NULL) ? true : false;
|
||||
return (fake_clipboard != NULL);
|
||||
}
|
||||
|
||||
#if defined(GUTLOS_FUNCS)
|
||||
return (g_put_clip_text(buf) == 0) ? true : false;
|
||||
return (g_put_clip_text(buf) == 0);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
@@ -191,7 +191,7 @@ void g_set_osicon(void) {
|
||||
|
||||
bool g_is_clip_available(void) {
|
||||
|
||||
return (winapi == NOAPI) ? false : true;
|
||||
return make_bool_not(winapi == NOAPI);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -254,7 +254,7 @@ void g_set_osicon(void) {
|
||||
|
||||
bool g_is_clip_available(void) {
|
||||
|
||||
return (ge_os2_hab) ? true : false;
|
||||
return make_bool(ge_os2_hab);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1832,7 +1832,7 @@ void vcurset(int sline, int eline) {
|
||||
vposset(gvid->numrows-1, gvid->numcols-1);
|
||||
|
||||
cci.dwSize = (eline and sline) ? sline : 100;
|
||||
cci.bVisible = eline ? true : false;
|
||||
cci.bVisible = make_bool(eline);
|
||||
|
||||
SetConsoleCursorInfo(gvid_hout, &cci);
|
||||
|
||||
|
@@ -99,7 +99,7 @@ int gwildmatch::match_internal(const char* text, const char* pattern, bool ignor
|
||||
}
|
||||
return -1;
|
||||
case '[':
|
||||
reverse = p[1] == '^' ? true : false;
|
||||
reverse = (p[1] == '^');
|
||||
if(reverse) // Inverted character class
|
||||
p++;
|
||||
matched = false;
|
||||
|
@@ -48,17 +48,17 @@
|
||||
|
||||
static GOLD_INLINE int _wchkrow(int wrow) {
|
||||
|
||||
return ((wrow<0) or (wrow>((gwin.active->erow-gwin.active->border)-(gwin.active->srow+gwin.active->border)))) ? true : false;
|
||||
return ((wrow<0) or (wrow>((gwin.active->erow-gwin.active->border)-(gwin.active->srow+gwin.active->border))));
|
||||
}
|
||||
|
||||
static GOLD_INLINE int _wchkcol(int wcol) {
|
||||
|
||||
return ((wcol<0) or (wcol>((gwin.active->ecol-gwin.active->border)-(gwin.active->scol+gwin.active->border)))) ? true : false;
|
||||
return ((wcol<0) or (wcol>((gwin.active->ecol-gwin.active->border)-(gwin.active->scol+gwin.active->border))));
|
||||
}
|
||||
|
||||
static GOLD_INLINE int _wchkcoord(int wrow, int wcol) {
|
||||
|
||||
return (_wchkrow(wrow) or _wchkcol(wcol)) ? true : false;
|
||||
return (_wchkrow(wrow) or _wchkcol(wcol));
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ int wchkcoord(int wrow, int wcol) {
|
||||
|
||||
int wchkbox(int wsrow, int wscol, int werow, int wecol) {
|
||||
|
||||
return (_wchkcoord(wsrow,wscol) or _wchkcoord(werow,wecol) or (wsrow>werow) or (wscol>wecol)) ? true : false;
|
||||
return (_wchkcoord(wsrow,wscol) or _wchkcoord(werow,wecol) or (wsrow>werow) or (wscol>wecol));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -165,7 +165,7 @@ void GMnu::SetTag(int tag) {
|
||||
|
||||
void GMnu::Begin(int type) {
|
||||
|
||||
int was_horz = (stack[depth].type&M_HORZ) ? true : false;
|
||||
bool was_horz = make_bool(stack[depth].type & M_HORZ);
|
||||
depth++;
|
||||
stack[depth].tag = -1;
|
||||
stack[depth].type = type | M_SAVE;
|
||||
|
@@ -1009,12 +1009,12 @@ bool gwinput::field::delete_word(bool left) {
|
||||
|
||||
if(entry != gwinput::entry_noedit) {
|
||||
|
||||
bool state = isspace(buf[buf_pos-((int) left)]) ? true : false;
|
||||
bool state = make_bool(isspace(buf[buf_pos-((int) left)]));
|
||||
|
||||
while(left ? buf_pos > 0 : buf_pos < buf_end_pos) {
|
||||
left ? delete_left() : delete_char();
|
||||
|
||||
if((isspace(buf[buf_pos-((int) left)]) ? true : false) != state)
|
||||
if(make_bool(isspace(buf[buf_pos-((int) left)])) != state)
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user