Skip to content

Commit 72d4687

Browse files
committed
perf: shared object find optimizations
when an econ item view goes looking for a econ item, it looks through the CSharedObjectTypeCache ideally, this would maintain a map instead of looking up with O(n) search, but that's a more complicated and scary change instead, skip the amount of virtual GetTypeID calls since SharedObject::BIsKeyEqual is only used in CSharedObjectTypeCache so the equal types are guaranteed. on GC, BIsKeyEqual is used in CSharedObjectTransaction as well, so we keep the old check for it. also move to a static_cast for CEconItem to be explicit/efficient with casting
1 parent d2153af commit 72d4687

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/game/shared/econ/econ_item.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ bool CEconItem::BAddDestroyToMessage( std::string *pBuffer ) const
15091509
bool CEconItem::BIsKeyLess( const CSharedObject & soRHS ) const
15101510
{
15111511
Assert( GetTypeID() == soRHS.GetTypeID() );
1512-
const CEconItem & soSchemaRHS = (const CEconItem &)soRHS;
1512+
const CEconItem & soSchemaRHS = static_cast<const CEconItem &>(soRHS);
15131513

15141514
return m_ulID < soSchemaRHS.m_ulID;
15151515
}

src/gcsdk/sharedobject.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,13 @@ const char *CSharedObject::PchClassUpdateNodeName( int nTypeID )
113113
bool CSharedObject::BIsKeyEqual( const CSharedObject & soRHS ) const
114114
{
115115
// Make sure they are the same type.
116+
#ifdef GC
116117
if ( GetTypeID() != soRHS.GetTypeID() )
117118
return false;
119+
#else
120+
// BIsKeyEqual is only used for objects of the same type within their CSharedObjectTypeCache.
121+
Assert ( GetTypeID() == soRHS.GetTypeID() );
122+
#endif
118123

119124
return !BIsKeyLess( soRHS ) && !soRHS.BIsKeyLess( *this );
120125
}

0 commit comments

Comments
 (0)