diff --git a/libr/cons/cons.c b/libr/cons/cons.c index 8b7bf80ecf4ad..f3f169071fef6 100644 --- a/libr/cons/cons.c +++ b/libr/cons/cons.c @@ -433,7 +433,7 @@ R_API bool r_cons_is_breaked(void) { if (I->cb_break) { I->cb_break (I->user); } - if (I->timeout) { + if (R_UNLIKELY (I->timeout)) { if (r_time_now_mono () > I->timeout) { C->breaked = true; C->was_breaked = true; @@ -441,7 +441,7 @@ R_API bool r_cons_is_breaked(void) { I->timeout = 0; } } - if (!C->was_breaked) { + if (R_UNLIKELY (!C->was_breaked)) { C->was_breaked = C->breaked; } return C && C->breaked; @@ -477,9 +477,9 @@ R_API int r_cons_get_cur_line(void) { if (isatty (fileno (stdin))) { if (write (1, R_CONS_GET_CURSOR_POSITION, sizeof (R_CONS_GET_CURSOR_POSITION)) != -1) { if (read (0, buf, sizeof (buf)) != sizeof (buf)) { - if (isdigit ((unsigned char)buf[2])) { + if (isdigit ((ut8)buf[2])) { curline = (buf[2] - '0'); - } if (isdigit ((unsigned char)buf[3])) { + } if (isdigit ((ut8)buf[3])) { curline = curline * 10 + (buf[3] - '0'); } } diff --git a/libr/core/anal_tp.c b/libr/core/anal_tp.c index 62970bb7ea2d9..f87943917366c 100644 --- a/libr/core/anal_tp.c +++ b/libr/core/anal_tp.c @@ -15,9 +15,9 @@ static bool anal_emul_init(RCore *core, RConfigHold *hc, RDebugTrace **dt, RAnal core->dbg->trace = r_debug_trace_new (); core->anal->esil->trace = r_anal_esil_trace_new (core->anal->esil); r_config_hold (hc, "esil.romem", "dbg.trace", "esil.nonull", "dbg.follow", NULL); - r_config_set (core->config, "esil.romem", "true"); - r_config_set (core->config, "dbg.trace", "true"); - r_config_set (core->config, "esil.nonull", "true"); + r_config_set_b (core->config, "esil.romem", true); + r_config_set_b (core->config, "dbg.trace", true); + r_config_set_b (core->config, "esil.nonull", true); r_config_set_i (core->config, "dbg.follow", false); const char *bp = r_reg_get_name (core->anal->reg, R_REG_NAME_BP); const char *sp = r_reg_get_name (core->anal->reg, R_REG_NAME_SP); diff --git a/libr/core/cmd_anal.c b/libr/core/cmd_anal.c index 270d054194b3c..50bb94c312b78 100644 --- a/libr/core/cmd_anal.c +++ b/libr/core/cmd_anal.c @@ -7507,7 +7507,7 @@ static void cmd_anal_esil(RCore *core, const char *input, bool verbose) { if (!esil->trace) { break; } - r_config_set_i (core->config, "dbg.trace", true); + r_config_set_b (core->config, "dbg.trace", true); break; case '-': // "aets-" if (!esil) { @@ -7520,7 +7520,7 @@ static void cmd_anal_esil(RCore *core, const char *input, bool verbose) { } r_anal_esil_trace_free (esil->trace); esil->trace = NULL; - r_config_set_i (core->config, "dbg.trace", false); + r_config_set_b (core->config, "dbg.trace", false); break; default: r_core_cmd_help (core, help_msg_aets); diff --git a/libr/debug/trace.c b/libr/debug/trace.c index 952372e632d17..7852ca0fbd396 100644 --- a/libr/debug/trace.c +++ b/libr/debug/trace.c @@ -185,9 +185,9 @@ R_API void r_debug_trace_op(RDebug *dbg, RAnalOp *op) { eprintf ("Run aeim to get dbg->anal->esil initialized\n"); } } - } - if (oldpc != UT64_MAX) { - r_debug_trace_add (dbg, oldpc, op->size); //XXX review what this line really do + if (oldpc != UT64_MAX) { + r_debug_trace_add (dbg, oldpc, op->size); //XXX review what this line really do + } } oldpc = op->addr; } @@ -263,7 +263,7 @@ R_API void r_debug_trace_list(RDebug *dbg, int mode, ut64 offset) { } // XXX: find better name, make it public? -static int r_debug_trace_is_traceable(RDebug *dbg, ut64 addr) { +static bool r_debug_trace_is_traceable(RDebug *dbg, ut64 addr) { if (dbg->trace->addresses) { char addr_str[32]; snprintf (addr_str, sizeof (addr_str), "0x%08"PFMT64x, addr); diff --git a/libr/include/r_types_base.h b/libr/include/r_types_base.h index 4065f7b9c3c9b..bb10dcc2da96e 100644 --- a/libr/include/r_types_base.h +++ b/libr/include/r_types_base.h @@ -27,6 +27,14 @@ extern "C" { # define R_ALIGNED(x) __attribute__((aligned(x))) #endif +#if defined(__GNUC__) +#define R_LIKELY(x) __builtin_expect((x),1) +#define R_UNLIKELY(x) __builtin_expect((x),0) +#else +#define R_LIKELY(x) (x) +#define R_UNLIKELY(x) (x) +#endif + #define R_IGNORE_RETURN(x) if ((x)) {;} typedef R_ALIGNED(1) ut16 uut16; diff --git a/shlr/sdb/src/ht.inc b/shlr/sdb/src/ht.inc index 03e1132a9c71b..08b27c6b85abc 100644 --- a/shlr/sdb/src/ht.inc +++ b/shlr/sdb/src/ht.inc @@ -201,12 +201,14 @@ static HT_(Kv) *reserve_kv(HtName_(Ht) *ht, const KEY_TYPE key, const int key_le } } - HT_(Kv) *newkvarr = (HT_(Kv)*)realloc (bt->arr, (bt->count + 1) * ht->opt.elem_size); - if (!newkvarr) { - return NULL; + if (bt->count + 1 >= bt->size) { + bt->size = (bt->count + 5) * 2; + HT_(Kv) *newkvarr = (HT_(Kv)*)realloc (bt->arr, (bt->size) * ht->opt.elem_size); + if (!newkvarr) { + return NULL; + } + bt->arr = newkvarr; } - - bt->arr = newkvarr; bt->count++; ht->count++; return kv_at (ht, bt, bt->count - 1); diff --git a/shlr/sdb/src/ht_inc.h b/shlr/sdb/src/ht_inc.h index 86ae08dca8f1a..d019d210a518d 100644 --- a/shlr/sdb/src/ht_inc.h +++ b/shlr/sdb/src/ht_inc.h @@ -73,6 +73,7 @@ typedef bool (*HT_(ForeachCallback))(void *user, const KEY_TYPE, const VALUE_TYP typedef struct Ht_(bucket_t) { HT_(Kv) *arr; ut32 count; + ut32 size; } HT_(Bucket); /* Options contain all the settings of the hashtable */ diff --git a/shlr/sdb/src/util.c b/shlr/sdb/src/util.c index 6756c9541985d..28b94fdc9382d 100644 --- a/shlr/sdb/src/util.c +++ b/shlr/sdb/src/util.c @@ -21,7 +21,7 @@ struct timezone { SDB_API int gettimeofday(struct timeval* p, struct timezone * tz) { //ULARGE_INTEGER ul; // As specified on MSDN. ut64 ul = 0; - static int tzflag = 0; + static bool tzflag = false; FILETIME ft; if (p) { // Returns a 64-bit value representing the number of @@ -49,7 +49,7 @@ SDB_API int gettimeofday(struct timeval* p, struct timezone * tz) { if (tz) { if (!tzflag) { _tzset (); - tzflag++; + tzflag = true; } tz->tz_minuteswest = _timezone / 60; tz->tz_dsttime = _daylight;