Skip to content

Commit

Permalink
Minor optimization in r_io_bank_overlay_foreach ##io
Browse files Browse the repository at this point in the history
  • Loading branch information
condret committed Dec 10, 2024
1 parent 9f085e0 commit d03e7f3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion libr/core/cmd_open.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ static void cmd_open_banks(RCore *core, int argc, char *argv[]) {
}
}

static void overlay_print_diff_cb (RInterval itv, const ut8 *m_data, const ut8 *o_data, void *user) {
static void overlay_print_diff_cb(RInterval itv, const ut8 *m_data, const ut8 *o_data, void *user) {
// RCore *core = user;
char *m_hex = r_hex_bin2strdup (m_data, r_itv_size (itv));
char *o_hex = r_hex_bin2strdup (o_data, r_itv_size (itv));
Expand Down
31 changes: 23 additions & 8 deletions libr/io/io_bank.c
Original file line number Diff line number Diff line change
Expand Up @@ -939,27 +939,42 @@ static void bof_cb (RInterval itv, const ut8 *data, void *user) {
return;
}
RInterval ov_itv = r_itv_intersect (itv, bof->sm->itv);
ut8 *m_data = R_NEWS (ut8, r_itv_size (ov_itv));
if (!m_data) {
return;
union {
ut8 data[sizeof (ut8 *)];
ut8 *ptr;
} m;
if (R_UNLIKELY (r_itv_size (ov_itv) > sizeof (ut8 *))) {
m.ptr = R_NEWS (ut8, r_itv_size (ov_itv));
if (!m.ptr) {
return;
}
}
const ut8 *o_data = &data[
(r_itv_begin (itv) < r_itv_begin (ov_itv))?
(r_itv_begin (ov_itv) - r_itv_begin (itv)): 0];
const ut64 pa = r_itv_begin (ov_itv) - r_io_map_from (bof->map) + bof->map->delta;
if (r_io_fd_read_at (bof->io, bof->map->fd, pa, m_data, r_itv_size (ov_itv)) != r_itv_size (ov_itv)) {
if (R_UNLIKELY (r_itv_size (ov_itv) > sizeof (ut8 *))) {
if (r_io_fd_read_at (bof->io, bof->map->fd, pa, m.ptr,
r_itv_size (ov_itv)) != r_itv_size (ov_itv)) {
R_LOG_WARN ("r_io_fd_read_at failed");
free (m.ptr);
return;
}
bof->cb (ov_itv, m.ptr, o_data, bof->user);
free (m.ptr);
return;
}
if (r_io_fd_read_at (bof->io, bof->map->fd, pa, m.data, r_itv_size (ov_itv)) != r_itv_size (ov_itv)) {
R_LOG_WARN ("r_io_fd_read_at failed");
free (m_data);
return;
}
bof->cb (ov_itv, m_data, o_data, bof->user);
free (m_data);
bof->cb (ov_itv, m.data, o_data, bof->user);
}

R_API void r_io_bank_overlay_foreach(RIO *io, const ut32 bankid, RIOOverlayForeach cb, void *user) {
R_RETURN_IF_FAIL (io && cb);
RIOBank *bank = r_io_bank_get (io, bankid);
if (!bank || !bank->submaps || !bank->submaps->size) {
if (!io->overlay || !bank || !bank->submaps || !bank->submaps->size) {
return;
}
RRBNode *node = r_crbtree_first_node (bank->submaps);
Expand Down

0 comments on commit d03e7f3

Please sign in to comment.