Cleanup: reduce indentation with early returns in allocimbuf
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user