engine: imagelib: super micro-optimization, reallocate buffer in Image_Copy rather than allocating and copying

This commit is contained in:
Alibek Omarov 2024-07-16 05:10:29 +03:00
parent 147e5dceff
commit a09084ceba

View file

@ -174,8 +174,8 @@ byte *Image_Copy( size_t size )
{ {
byte *out; byte *out;
out = Mem_Malloc( host.imagepool, size ); out = Mem_Realloc( host.imagepool, image.tempbuffer, size );
memcpy( out, image.tempbuffer, size ); image.tempbuffer = NULL;
return out; return out;
} }
@ -1374,20 +1374,20 @@ static qboolean Image_RemapInternal( rgbdata_t *pic, int topColor, int bottomCol
return true; return true;
} }
qboolean Image_Process(rgbdata_t **pix, int width, int height, uint flags, float reserved ) qboolean Image_Process( rgbdata_t **pix, int width, int height, uint flags, float reserved )
{ {
rgbdata_t *pic = *pix; rgbdata_t *pic = *pix;
qboolean result = true; qboolean result = true;
byte *out; byte *out;
// check for buffers // check for buffers
if( !pic || !pic->buffer ) if( unlikely( !pic || !pic->buffer ))
{ {
image.force_flags = 0; image.force_flags = 0;
return false; return false;
} }
if( !flags ) if( unlikely( !flags ))
{ {
// clear any force flags // clear any force flags
image.force_flags = 0; image.force_flags = 0;
@ -1432,7 +1432,7 @@ qboolean Image_Process(rgbdata_t **pix, int width, int height, uint flags, float
pic->width = w, pic->height = h; pic->width = w, pic->height = h;
pic->size = w * h * PFDesc[pic->type].bpp; pic->size = w * h * PFDesc[pic->type].bpp;
Mem_Free( pic->buffer ); // free original image buffer Mem_Free( pic->buffer ); // free original image buffer
pic->buffer = Image_Copy( pic->size ); // unzone buffer (don't touch image.tempbuffer) pic->buffer = Image_Copy( pic->size ); // unzone buffer
} }
else else
{ {