Cleanup: Use const argument, decrease variable scope

This commit is contained in:
Hans Goudey 2021-02-17 16:42:20 -06:00
parent fd75f7c135
commit 5fef212e31
2 changed files with 6 additions and 11 deletions

View File

@ -1411,7 +1411,7 @@ enum {
UI_TEMPLATE_ID_FILTER_AVAILABLE = 1,
};
int UI_icon_from_id(struct ID *id);
int UI_icon_from_id(const struct ID *id);
int UI_icon_from_report_type(int type);
int UI_icon_colorid_from_report_type(int type);
int UI_text_colorid_from_report_type(int type);

View File

@ -511,21 +511,15 @@ void ui_rna_collection_search_update_fn(const struct bContext *C,
}
/***************************** ID Utilities *******************************/
int UI_icon_from_id(ID *id)
int UI_icon_from_id(const ID *id)
{
Object *ob;
PointerRNA ptr;
short idcode;
if (id == NULL) {
return ICON_NONE;
}
idcode = GS(id->name);
/* exception for objects */
if (idcode == ID_OB) {
ob = (Object *)id;
if (GS(id->name) == ID_OB) {
Object *ob = (Object *)id;
if (ob->type == OB_EMPTY) {
return ICON_EMPTY_DATA;
@ -535,7 +529,8 @@ int UI_icon_from_id(ID *id)
/* otherwise get it through RNA, creating the pointer
* will set the right type, also with subclassing */
RNA_id_pointer_create(id, &ptr);
PointerRNA ptr;
RNA_id_pointer_create((ID *)id, &ptr);
return (ptr.type) ? RNA_struct_ui_icon(ptr.type) : ICON_NONE;
}