From 9ebdc72404dfc603d5200a241b4cdefeb8f22acb Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Fri, 27 Feb 2009 00:01:38 +0100 Subject: [PATCH] ResourcesDB: added nameHash property in order to avoid unnecessary string comparisons (now comparing two int's before comparing two whole string objects) --- include/resources_db.h | 8 ++++++++ src/core/resources_db.cpp | 11 ++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/resources_db.h b/include/resources_db.h index a83b2ce8b..cdd26be6a 100644 --- a/include/resources_db.h +++ b/include/resources_db.h @@ -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; diff --git a/src/core/resources_db.cpp b/src/core/resources_db.cpp index 51f2573b6..10c845fe3 100644 --- a/src/core/resources_db.cpp +++ b/src/core/resources_db.cpp @@ -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 ) {