Skip to content

Commit 90058f6

Browse files
committed
filesystem: Speedup CBaseFileSystem::GetSearchPath a bit by using preallocated capacity std::string
1 parent f62b6d6 commit 90058f6

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

filesystem/basefilesystem.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,17 +1459,15 @@ int CBaseFileSystem::GetSearchPath( const char *pathID, bool bGetPackFiles, OUT_
14591459
{
14601460
AUTO_LOCK( m_SearchPathsMutex );
14611461

1462-
if ( maxLenInChars )
1463-
{
1464-
pDest[0] = 0;
1465-
}
1466-
14671462
// Build up result into string object
1468-
CUtlString sResult;
1463+
// dimhotepus: Use std::string and reserve capacity.
1464+
std::string sResult;
1465+
sResult.reserve(maxLenInChars);
1466+
14691467
CSearchPathsIterator iter( this, pathID, bGetPackFiles ? FILTER_NONE : FILTER_CULLPACK );
14701468
for ( CSearchPath *pSearchPath = iter.GetFirst(); pSearchPath != nullptr; pSearchPath = iter.GetNext() )
14711469
{
1472-
if ( !sResult.IsEmpty() )
1470+
if ( !sResult.empty() )
14731471
sResult += ";";
14741472
if ( pSearchPath->GetPackFile() )
14751473
{
@@ -1491,11 +1489,11 @@ int CBaseFileSystem::GetSearchPath( const char *pathID, bool bGetPackFiles, OUT_
14911489
// Copy into user's buffer, possibly truncating
14921490
if ( maxLenInChars )
14931491
{
1494-
V_strncpy( pDest, sResult.String(), maxLenInChars );
1492+
V_strncpy( pDest, sResult.c_str(), maxLenInChars );
14951493
}
14961494

14971495
// Return 1 extra for the nullptr terminator
1498-
return sResult.Length()+1;
1496+
return sResult.size()+1;
14991497
}
15001498

15011499

0 commit comments

Comments
 (0)