ResourcesDB: added nameHash property in order to avoid unnecessary

string comparisons (now comparing two int's before comparing two whole
string objects)
This commit is contained in:
Tobias Doerffel
2009-02-27 00:01:38 +01:00
parent 57c7c64103
commit 9ebdc72404
2 changed files with 16 additions and 3 deletions

View File

@@ -84,6 +84,7 @@ public:
int _size = -1,
const QDateTime & _last_mod = QDateTime() ) :
m_name( _name ),
m_nameHash( 0 ),
m_type( _type ),
m_baseDir( _base_dir ),
m_path( _path ),
@@ -98,6 +99,7 @@ public:
Item() :
m_name(),
m_nameHash( 0 ),
m_type( TypeUnknown ),
m_baseDir( BaseRoot ),
m_path(),
@@ -116,6 +118,11 @@ public:
return m_name;
}
inline int nameHash( void ) const
{
return m_nameHash;
}
Types type( void ) const
{
return m_type;
@@ -206,6 +213,7 @@ public:
void init( void );
QString m_name;
int m_nameHash;
Types m_type;
BaseDirectories m_baseDir;
QString m_path;

View File

@@ -43,7 +43,8 @@ void ResourcesDB::Item::reload( void )
bool ResourcesDB::Item::operator==( const Item & _other ) const
{
return m_name == _other.m_name &&
return m_nameHash == _other.m_nameHash &&
m_name == _other.m_name &&
m_type == _other.m_type &&
m_path == _other.m_path &&
m_hash == _other.m_hash &&
@@ -57,12 +58,13 @@ bool ResourcesDB::Item::operator==( const Item & _other ) const
int ResourcesDB::Item::equalityLevel( const Item & _other ) const
{
int l = 0;
if( m_name == _other.m_name &&
if( m_nameHash == _other.m_nameHash &&
m_name == _other.m_name &&
m_path == _other.m_path )
{
l += 40;
}
else if( m_name == _other.m_name )
else if( m_nameHash == _other.m_nameHash && m_name == _other.m_name )
{
l += 30;
}
@@ -210,6 +212,8 @@ void ResourcesDB::Item::init( void )
m_hash = h.result().toHex();
}
}
m_nameHash = qHash( m_name );
}
@@ -261,6 +265,7 @@ ResourcesDB::TreeItem * ResourcesDB::TreeItem::findChild(
{
TreeItem * ti = *it;
if( ti->item() &&
ti->item()->nameHash() == hash &&
ti->item()->name() == _name &&
ti->item()->baseDir() == _base_dir )
{