SVN commit 547148 by zwabel: little optimization M +23 -6 message.h M +2 -0 network.kdevelop M +1 -0 sharedptr.h --- branches/work/kdevelop-teamwork/network/message.h #547147:547148 @@ -35,18 +35,36 @@ typedef std::vector IdList; private: IdList idList_; + unsigned int fastId_; ///can only be used when the idList has <= 4 entries + bool useFastId; + void packFastId() { + fastId_ = 0; + if( idList_.size() > 4 ) { + useFastId = false; + } else { + useFastId = true; + int shift = 24; + for( IdList::iterator it = idList_.begin(); it != idList_.end(); ++it ) { + fastId_ += *it << shift; + shift -= 8; + } + } + } public: - MessageId( IdList IDs = IdList() ) { + MessageId( IdList IDs = IdList() ) : useFastId(false) { idList_ = IDs; + packFastId(); } - MessageId( InArchive& from ) { + MessageId( InArchive& from ): useFastId(false) { from >> idList_; + packFastId(); } void serialize( OutArchive& target, int version ) const { target << idList_; } bool operator < ( const MessageId& rhs ) const { + if( useFastId && rhs.useFastId ) return fastId_ < rhs.fastId_; int s1 = idList_.size(); int s2 = rhs.idList_.size(); int ms = s2 > s1 ? s1 : s2; @@ -69,11 +87,13 @@ MessageId& operator += ( unsigned char append ) { idList_.push_back( append ); + packFastId(); return *this; } MessageId& operator -- () { if( !idList_.empty() ) idList_.pop_back(); + packFastId(); return *this; } @@ -200,10 +220,7 @@ } }; - /**This allows multiple differing dispatch-targets(like the server + the thread). - those should not be derived from each other, since they are identified by using dynamic_cast - This class is designed to be thread-safe as long as no new types are added - */ + /**This allows multiple differing dispatch-targets(like the server + the thread). */ template class MessageTypeSet : public MessageTypeSetInterface { typedef std::map* > TypeMap; --- branches/work/kdevelop-teamwork/network/network.kdevelop #547147:547148 @@ -85,6 +85,8 @@ STL Common-C++ + g++ + Boost-Serialization false --- branches/work/kdevelop-teamwork/network/sharedptr.h #547147:547148 @@ -23,6 +23,7 @@ + /** * Warning: Not thread-safe: use SafeShared for thread-safe reference-counting. * Reference counting for shared objects. If you derive your object