engine: common: optimize COM_LoadFile/COM_LoadFileForMe removing double allocation
This commit is contained in:
parent
636a2228f6
commit
491b503f96
1 changed files with 2 additions and 14 deletions
|
@ -693,7 +693,7 @@ COM_LoadFileForMe
|
||||||
byte *GAME_EXPORT COM_LoadFileForMe( const char *filename, int *pLength )
|
byte *GAME_EXPORT COM_LoadFileForMe( const char *filename, int *pLength )
|
||||||
{
|
{
|
||||||
string name;
|
string name;
|
||||||
byte *file, *pfile;
|
byte *pfile;
|
||||||
fs_offset_t iLength;
|
fs_offset_t iLength;
|
||||||
|
|
||||||
if( !COM_CheckString( filename ))
|
if( !COM_CheckString( filename ))
|
||||||
|
@ -706,21 +706,9 @@ byte *GAME_EXPORT COM_LoadFileForMe( const char *filename, int *pLength )
|
||||||
Q_strncpy( name, filename, sizeof( name ));
|
Q_strncpy( name, filename, sizeof( name ));
|
||||||
COM_FixSlashes( name );
|
COM_FixSlashes( name );
|
||||||
|
|
||||||
pfile = FS_LoadFile( name, &iLength, false );
|
pfile = g_fsapi.LoadFileMalloc( name, &iLength, false );
|
||||||
if( pLength ) *pLength = (int)iLength;
|
if( pLength ) *pLength = (int)iLength;
|
||||||
|
|
||||||
if( pfile )
|
|
||||||
{
|
|
||||||
file = malloc( iLength + 1 );
|
|
||||||
if( file != NULL )
|
|
||||||
{
|
|
||||||
memcpy( file, pfile, iLength );
|
|
||||||
file[iLength] = '\0';
|
|
||||||
}
|
|
||||||
Mem_Free( pfile );
|
|
||||||
pfile = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pfile;
|
return pfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue