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. Signed-off-by: Bin Guo <guobin@linux.alibaba.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20260401100005.20651-1-guobin@linux.alibaba.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Bin Guo committed
Apr 1, 2026 at 18:00 UTC
bf7ce99494a217beb6cebc27589e263c22c146f8
1 file changed
+5
-11
system/physmem.c
+5
-11
@@ -981,17 +981,11 @@ uint8_t physical_memory_range_includes_clean(ram_addr_t start,
981
{
982
uint8_t ret = 0;
983
984
- if (mask & (1 << DIRTY_MEMORY_VGA) &&
985
- !physical_memory_all_dirty(start, length, DIRTY_MEMORY_VGA)) {
986
- ret |= (1 << DIRTY_MEMORY_VGA);
987
- }
988
- if (mask & (1 << DIRTY_MEMORY_CODE) &&
989
- !physical_memory_all_dirty(start, length, DIRTY_MEMORY_CODE)) {
990
- ret |= (1 << DIRTY_MEMORY_CODE);
991
- }
992
- if (mask & (1 << DIRTY_MEMORY_MIGRATION) &&
993
- !physical_memory_all_dirty(start, length, DIRTY_MEMORY_MIGRATION)) {
994
- ret |= (1 << DIRTY_MEMORY_MIGRATION);
984
+ for (int i = 0; i < DIRTY_MEMORY_NUM; i++) {
985
+ if ((mask & (1 << i)) &&
986
+ !physical_memory_all_dirty(start, length, i)) {
987
+ ret |= (1 << i);
988
+ }
989
}
990
return ret;
991
}