Cleanup: reduce indentation with early returns in allocimbuf

This commit is contained in:
Campbell Barton
2023-05-04 13:18:42 +10:00
parent cf16eab370
commit 4395a35641

View File

@@ -165,29 +165,31 @@ void imb_freerectImbuf_all(ImBuf *ibuf)
void IMB_freeImBuf(ImBuf *ibuf)
{
if (ibuf) {
bool needs_free = false;
if (ibuf == nullptr) {
return;
}
BLI_spin_lock(&refcounter_spin);
if (ibuf->refcounter > 0) {
ibuf->refcounter--;
}
else {
needs_free = true;
}
BLI_spin_unlock(&refcounter_spin);
bool needs_free = false;
if (needs_free) {
imb_freerectImbuf_all(ibuf);
IMB_metadata_free(ibuf->metadata);
colormanage_cache_free(ibuf);
BLI_spin_lock(&refcounter_spin);
if (ibuf->refcounter > 0) {
ibuf->refcounter--;
}
else {
needs_free = true;
}
BLI_spin_unlock(&refcounter_spin);
if (ibuf->dds_data.data != nullptr) {
/* dds_data.data is allocated by DirectDrawSurface::readData(), so don't use MEM_freeN! */
free(ibuf->dds_data.data);
}
MEM_freeN(ibuf);
if (needs_free) {
imb_freerectImbuf_all(ibuf);
IMB_metadata_free(ibuf->metadata);
colormanage_cache_free(ibuf);
if (ibuf->dds_data.data != nullptr) {
/* dds_data.data is allocated by DirectDrawSurface::readData(), so don't use MEM_freeN! */
free(ibuf->dds_data.data);
}
MEM_freeN(ibuf);
}
}
@@ -200,22 +202,18 @@ void IMB_refImBuf(ImBuf *ibuf)
ImBuf *IMB_makeSingleUser(ImBuf *ibuf)
{
ImBuf *rval;
if (ibuf) {
bool is_single;
BLI_spin_lock(&refcounter_spin);
is_single = (ibuf->refcounter == 0);
BLI_spin_unlock(&refcounter_spin);
if (is_single) {
return ibuf;
}
}
else {
if (ibuf == nullptr) {
return nullptr;
}
rval = IMB_dupImBuf(ibuf);
BLI_spin_lock(&refcounter_spin);
const bool is_single = (ibuf->refcounter == 0);
BLI_spin_unlock(&refcounter_spin);
if (is_single) {
return ibuf;
}
ImBuf *rval = IMB_dupImBuf(ibuf);
IMB_metadata_copy(rval, ibuf);