diff --git a/libr/io/io_cache.c b/libr/io/io_cache.c index 1f3f9b1e28..0e9c640988 100644 --- a/libr/io/io_cache.c +++ b/libr/io/io_cache.c @@ -378,18 +378,10 @@ R_API bool r_io_cache_write_at(RIO *io, ut64 addr, ut8 *buf, int len) { R_API bool r_io_cache_read_at(RIO *io, ut64 addr, ut8 *buf, int len) { r_return_val_if_fail (io && buf && (len > 0), false); - bool ret = true; - if (io->va) { - ret = r_io_bank_read_at (io, io->bank, addr, buf, len); - } else if (io->desc) { - ret = (r_io_desc_read_at (io->desc, addr, buf, len) > 0); - } - if (!ret) { - return false; - } RInterval itv = (RInterval){addr, len}; RRBNode *node = _find_entry_ci_node (io->cache->tree, &itv); IOCacheItem *ci = node? (IOCacheItem *)node->data: NULL; + const bool ret = !!ci; while (ci && r_itv_overlap (ci->tree_itv[0], itv)) { node = r_rbnode_next (node); RInterval its = r_itv_intersect (ci->tree_itv[0], itv); @@ -398,7 +390,7 @@ R_API bool r_io_cache_read_at(RIO *io, ut64 addr, ut8 *buf, int len) { r_itv_size (its)); ci = node? (IOCacheItem *)node->data: NULL; } - return true; + return ret; } R_API bool r_io_cache_at(RIO *io, ut64 addr) { diff --git a/libr/io/io_desc.c b/libr/io/io_desc.c index 879723d9b1..f04faa72e5 100644 --- a/libr/io/io_desc.c +++ b/libr/io/io_desc.c @@ -201,15 +201,8 @@ R_API int r_io_desc_read(RIODesc *desc, ut8 *buf, int len) { return -1; } ut64 seek = r_io_desc_seek (desc, 0LL, R_IO_SEEK_CUR); - if (desc->io->cachemode) { - if (seek != UT64_MAX && r_io_cache_at (desc->io, seek)) { - return r_io_cache_read (desc->io, seek, buf, len); - } - } int ret = r_io_plugin_read (desc, buf, len); - if (ret > 0 && desc->io->cachemode) { - r_io_cache_write (desc->io, seek, buf, len); - } else if ((ret > 0) && desc->io && (desc->io->p_cache & 1)) { + if ((ret > 0) && desc->io && (desc->io->p_cache & 1)) { ret = r_io_desc_cache_read (desc, seek, buf, ret); } return ret;