physmem: Simplify dirty memory type checks with loop
PATCH 1/1 physmem: Simplify dirty memory type checks with loop
In physical_memory_range_includes_clean(), we have three nearly identical if-statements checking different DIRTY_MEMORY types (VGA, CODE, MIGRATION). This code duplication makes maintenance harder and increases the risk of inconsistencies when adding new dirty memory types.
Replace the repetitive checks with a simple loop that iterates through all DIRTY_MEMORY_NUM types, checking only those specified in the mask. This reduces code size and makes it easier to add new dirty memory types in the future.
--- system/physmem.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
system/physmem.c +5 -11
@@ -981,17 +981,11 @@ uint8_t physical_memory_range_includes_clean(ram_addr_t start, {uint8_t ret =0 ; -if (mask & (1 <<DIRTY_MEMORY_VGA ) && - !physical_memory_all_dirty (start, length,DIRTY_MEMORY_VGA )) { - ret |= (1 <<DIRTY_MEMORY_VGA ); - } -if (mask & (1 <<DIRTY_MEMORY_CODE ) && - !physical_memory_all_dirty (start, length,DIRTY_MEMORY_CODE )) { - ret |= (1 <<DIRTY_MEMORY_CODE ); - } -if (mask & (1 <<DIRTY_MEMORY_MIGRATION ) && - !physical_memory_all_dirty (start, length,DIRTY_MEMORY_MIGRATION )) { - ret |= (1 <<DIRTY_MEMORY_MIGRATION ); +for (int i =0 ; i <DIRTY_MEMORY_NUM ; i++) { +if ((mask & (1 << i)) && + !physical_memory_all_dirty (start, length, i)) { + ret |= (1 << i); + } }return ret; }
Signature · 1 line
2.50.1 (Apple Git-155)
Quoted 10 lines · Bin Guo
In
physical_memory_range_includes_clean(), we have three nearly identical if-statements checking differentDIRTY_MEMORYtypes (VGA, CODE, MIGRATION). This code duplication makes maintenance harder and increases the risk of inconsistencies when adding new dirty memory types.Replace the repetitive checks with a simple loop that iterates through all
DIRTY_MEMORY_NUMtypes, checking only those specified in the mask. This reduces code size and makes it easier to add new dirty memory types in the future.
Quoted 4 lines
Signed-off-by Bin Guo <[email protected]>--- system/physmem.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
Quoted 11 lines · Bin Guo
In
physical_memory_range_includes_clean(), we have three nearly identical if-statements checking differentDIRTY_MEMORYtypes (VGA, CODE, MIGRATION). This code duplication makes maintenance harder and increases the risk of inconsistencies when adding new dirty memory types.Replace the repetitive checks with a simple loop that iterates through all
DIRTY_MEMORY_NUMtypes, checking only those specified in the mask. This reduces code size and makes it easier to add new dirty memory types in the future.Signed-off-by Bin Guo <[email protected]>
Signature · 1 line
Peter Xu