From f369386d5af92c573504c235c1ce0eedccafde37 Mon Sep 17 00:00:00 2001 From: Alexander Romanov Date: Wed, 15 Apr 2026 13:44:29 +0300 Subject: [PATCH] refactor: remove excessive chunk_max_size calls These calls are virtual and cause notable overhead --- fesvr/htif.cc | 4 ++-- fesvr/memif.cc | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fesvr/htif.cc b/fesvr/htif.cc index 267bb498..26c3a3bf 100644 --- a/fesvr/htif.cc +++ b/fesvr/htif.cc @@ -277,8 +277,8 @@ void htif_t::clear_chunk(addr_t taddr, size_t len) { std::vector zeros(chunk_max_size(), 0); - for (size_t pos = 0; pos < len; pos += chunk_max_size()) - write_chunk(taddr + pos, std::min(len - pos, chunk_max_size()), &zeros[0]); + for (size_t pos = 0; pos < len; pos += zeros.size()) + write_chunk(taddr + pos, std::min(len - pos, zeros.size()), &zeros[0]); } int htif_t::run() diff --git a/fesvr/memif.cc b/fesvr/memif.cc index 59938b91..78107ce3 100644 --- a/fesvr/memif.cc +++ b/fesvr/memif.cc @@ -35,8 +35,9 @@ void memif_t::read(addr_t addr, size_t len, void* bytes) } // now we're aligned - for (size_t pos = 0; pos < len; pos += cmemif->chunk_max_size()) - cmemif->read_chunk(addr + pos, std::min(cmemif->chunk_max_size(), len - pos), (char*)bytes + pos); + size_t max_chunk = cmemif->chunk_max_size(); + for (size_t pos = 0; pos < len; pos += max_chunk) + cmemif->read_chunk(addr + pos, std::min(max_chunk, len - pos), (char*)bytes + pos); } void memif_t::write(addr_t addr, size_t len, const void* bytes)