From ff2d6c2ba8e8f667a0aac7a79c77b58d87f45a73 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 17 May 2022 15:08:18 +0200 Subject: Cleanup: Use `switch` and `BLI_assert_unreachable()` more. Replace some `if/else if` chains by proper `switch` statement. Replace some `BLI_assert(0)` calls by `BLI_assert_unreachable()` ones. --- source/blender/blenkernel/intern/icons.cc | 51 ++++++++++++++++--------------- 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'source/blender/blenkernel/intern/icons.cc') diff --git a/source/blender/blenkernel/intern/icons.cc b/source/blender/blenkernel/intern/icons.cc index 7826ef9b1f4..f59f5352aad 100644 --- a/source/blender/blenkernel/intern/icons.cc +++ b/source/blender/blenkernel/intern/icons.cc @@ -114,32 +114,35 @@ static void icon_free(void *val) static void icon_free_data(int icon_id, Icon *icon) { - if (icon->obj_type == ICON_DATA_ID) { - ((ID *)(icon->obj))->icon_id = 0; - } - else if (icon->obj_type == ICON_DATA_IMBUF) { - ImBuf *imbuf = (ImBuf *)icon->obj; - if (imbuf) { - IMB_freeImBuf(imbuf); + switch (icon->obj_type) { + case ICON_DATA_ID: + ((ID *)(icon->obj))->icon_id = 0; + break; + case ICON_DATA_IMBUF: { + ImBuf *imbuf = (ImBuf *)icon->obj; + if (imbuf) { + IMB_freeImBuf(imbuf); + } + break; } - } - else if (icon->obj_type == ICON_DATA_PREVIEW) { - ((PreviewImage *)(icon->obj))->icon_id = 0; - } - else if (icon->obj_type == ICON_DATA_GPLAYER) { - ((bGPDlayer *)(icon->obj))->runtime.icon_id = 0; - } - else if (icon->obj_type == ICON_DATA_GEOM) { - ((struct Icon_Geom *)(icon->obj))->icon_id = 0; - } - else if (icon->obj_type == ICON_DATA_STUDIOLIGHT) { - StudioLight *sl = (StudioLight *)icon->obj; - if (sl != nullptr) { - BKE_studiolight_unset_icon_id(sl, icon_id); + case ICON_DATA_PREVIEW: + ((PreviewImage *)(icon->obj))->icon_id = 0; + break; + case ICON_DATA_GPLAYER: + ((bGPDlayer *)(icon->obj))->runtime.icon_id = 0; + break; + case ICON_DATA_GEOM: + ((struct Icon_Geom *)(icon->obj))->icon_id = 0; + break; + case ICON_DATA_STUDIOLIGHT: { + StudioLight *sl = (StudioLight *)icon->obj; + if (sl != nullptr) { + BKE_studiolight_unset_icon_id(sl, icon_id); + } + break; } - } - else { - BLI_assert(0); + default: + BLI_assert_unreachable(); } } -- cgit v1.2.3