Skip to content

Commit

Permalink
register: refactor register_cache_invalidate()
Browse files Browse the repository at this point in the history
register_cache_invalidate() is written a way which uses
pointer arithmetic, which makes it harder to read. This patch
replaces it with more readable way to iterate over array of
structs.

Change-Id: Ia420f70a3bb6998c690c8c600c71301dca9f9dbf
Signed-off-by: Marek Vrbka <marek.vrbka@codasip.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7735
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
Reviewed-by: Jan Matyas <jan.matyas@codasip.com>
  • Loading branch information
MarekVCodasip authored and tom-van committed Aug 3, 2023
1 parent a510824 commit bab8b8c
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/target/register.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ void register_unlink_cache(struct reg_cache **cache_p, const struct reg_cache *c
/** Marks the contents of the register cache as invalid (and clean). */
void register_cache_invalidate(struct reg_cache *cache)
{
struct reg *reg = cache->reg_list;

for (unsigned int n = cache->num_regs; n != 0; n--, reg++) {
for (unsigned int n = 0; n < cache->num_regs; n++) {
struct reg *reg = &cache->reg_list[n];
if (!reg->exist)
continue;
reg->valid = false;
Expand Down

0 comments on commit bab8b8c

Please sign in to comment.