-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
Storage Engines
-
2
-
StorEng - Defined Pipeline
Summary
Whether or not a group of flags have been set is currently checked with a series of repetitive if statements. The aim of this ticket is to simplify and reduce the repetitive nature of the current code. This will inherently make the code less prone to copy-paste bugs, and be easier to extend on.
An example of what one of the current flag checks look like:
if (F_ISSET_ATOMIC_16(page, WT_PAGE_BUILD_KEYS)) WT_RET(ds->f(ds, ", keys-built")); if (F_ISSET_ATOMIC_16(page, WT_PAGE_DISK_ALLOC)) WT_RET(ds->f(ds, ", disk-alloc")); if (F_ISSET_ATOMIC_16(page, WT_PAGE_DISK_MAPPED)) WT_RET(ds->f(ds, ", disk-mapped")); if (F_ISSET_ATOMIC_16(page, WT_PAGE_EVICT_LRU)) WT_RET(ds->f(ds, ", evict-lru")); if (F_ISSET_ATOMIC_16(page, WT_PAGE_INTL_OVERFLOW_KEYS)) WT_RET(ds->f(ds, ", overflow-keys")); if (F_ISSET_ATOMIC_16(page, WT_PAGE_SPLIT_INSERT)) WT_RET(ds->f(ds, ", split-insert")); if (F_ISSET_ATOMIC_16(page, WT_PAGE_UPDATE_IGNORE)) WT_RET(ds->f(ds, ", update-ignore"));
Suggested approach
char *is_set[flag_count]; int is_set_count = 0; // find all flags that have been set for (int i = 0; i < flag_count; i++) { if (F_ISSET(ref, flags[i])) { is_set[i] = names[i]; is_set_count++; } else is_set[i] = NULL; } // print all flags that have been set (if needed) for (int i = 0; i < flag_count && is_set_count > 0; i++) { if (is_set[i]) { WT_RET(ds->f(ds, "%s", is_set[i])); is_set_count--; } // avoid trailing commas if (is_set_count > 0) WT_RET(ds->f(ds, "%s", ", ")); }
What is done?
Modify all similar instances of repetitive conditional flag checks to be:
- Easy to extend off i.e. how will the code change if we add more flags / flag checks
- Less repetitive and simplified logic