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;
out = Mem_Malloc( host.imagepool, size );
memcpy( out, image.tempbuffer, size );
out = Mem_Realloc( host.imagepool, image.tempbuffer, size );
image.tempbuffer = NULL;
return out;
}
@ -1381,13 +1381,13 @@ qboolean Image_Process(rgbdata_t **pix, int width, int height, uint flags, float
byte *out;
// check for buffers
if( !pic || !pic->buffer )
if( unlikely( !pic || !pic->buffer ))
{
image.force_flags = 0;
return false;
}
if( !flags )
if( unlikely( !flags ))
{
// clear any force flags
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->size = w * h * PFDesc[pic->type].bpp;
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
{