mirror of
https://github.com/YGGverse/xash3d-fwgs.git
synced 2025-01-19 19:40:21 +00:00
filesystem: dir.c: optimize string operations
This commit is contained in:
parent
24f7db19d8
commit
89807250e5
@ -57,21 +57,25 @@ void FS_Search_DIR( searchpath_t *search, stringlist_t *list, const char *patter
|
|||||||
slash = Q_strrchr( pattern, '/' );
|
slash = Q_strrchr( pattern, '/' );
|
||||||
backslash = Q_strrchr( pattern, '\\' );
|
backslash = Q_strrchr( pattern, '\\' );
|
||||||
colon = Q_strrchr( pattern, ':' );
|
colon = Q_strrchr( pattern, ':' );
|
||||||
|
|
||||||
separator = Q_max( slash, backslash );
|
separator = Q_max( slash, backslash );
|
||||||
separator = Q_max( separator, colon );
|
separator = Q_max( separator, colon );
|
||||||
|
|
||||||
basepathlength = separator ? (separator + 1 - pattern) : 0;
|
basepathlength = separator ? (separator + 1 - pattern) : 0;
|
||||||
basepath = Mem_Calloc( fs_mempool, basepathlength + 1 );
|
basepath = Mem_Calloc( fs_mempool, basepathlength + 1 );
|
||||||
if( basepathlength ) memcpy( basepath, pattern, basepathlength );
|
if( basepathlength ) memcpy( basepath, pattern, basepathlength );
|
||||||
basepath[basepathlength] = 0;
|
basepath[basepathlength] = '\0';
|
||||||
|
|
||||||
Q_sprintf( netpath, "%s%s", search->filename, basepath );
|
Q_strcpy( temp, basepath );
|
||||||
|
|
||||||
stringlistinit( &dirlist );
|
stringlistinit( &dirlist );
|
||||||
listdirectory( &dirlist, netpath, caseinsensitive );
|
listdirectory( &dirlist, netpath, caseinsensitive );
|
||||||
|
|
||||||
|
Q_strcpy( temp, basepath );
|
||||||
|
|
||||||
for( dirlistindex = 0; dirlistindex < dirlist.numstrings; dirlistindex++ )
|
for( dirlistindex = 0; dirlistindex < dirlist.numstrings; dirlistindex++ )
|
||||||
{
|
{
|
||||||
Q_sprintf( temp, "%s%s", basepath, dirlist.strings[dirlistindex] );
|
Q_strcpy( &temp[basepathlength], dirlist.strings[dirlistindex] );
|
||||||
|
|
||||||
if( matchpattern( temp, (char *)pattern, true ) )
|
if( matchpattern( temp, (char *)pattern, true ) )
|
||||||
{
|
{
|
||||||
@ -91,20 +95,18 @@ void FS_Search_DIR( searchpath_t *search, stringlist_t *list, const char *patter
|
|||||||
Mem_Free( basepath );
|
Mem_Free( basepath );
|
||||||
}
|
}
|
||||||
|
|
||||||
int FS_FileTime_DIR( struct searchpath_s *search, const char *filename )
|
int FS_FileTime_DIR( searchpath_t *search, const char *filename )
|
||||||
{
|
{
|
||||||
char path[MAX_SYSPATH];
|
char path[MAX_SYSPATH];
|
||||||
|
|
||||||
// found in the filesystem?
|
|
||||||
Q_sprintf( path, "%s%s", search->filename, filename );
|
Q_sprintf( path, "%s%s", search->filename, filename );
|
||||||
return FS_SysFileTime( path );
|
return FS_SysFileTime( path );
|
||||||
}
|
}
|
||||||
|
|
||||||
file_t *FS_OpenFile_DIR( struct searchpath_s *search, const char *filename, const char *mode, int pack_ind )
|
file_t *FS_OpenFile_DIR( searchpath_t *search, const char *filename, const char *mode, int pack_ind )
|
||||||
{
|
{
|
||||||
char path[MAX_SYSPATH];
|
char path[MAX_SYSPATH];
|
||||||
|
|
||||||
// found in the filesystem?
|
|
||||||
Q_sprintf( path, "%s%s", search->filename, filename );
|
Q_sprintf( path, "%s%s", search->filename, filename );
|
||||||
return FS_SysOpen( path, mode );
|
return FS_SysOpen( path, mode );
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user