From 8a4cd1aeca20992fdd6a0c6b6085f31ba9eaaa24 Mon Sep 17 00:00:00 2001 From: DarthArgus Date: Wed, 30 Nov 2016 23:04:10 +0000 Subject: [PATCH] c++11, love you... although this may end up duplicating some items on the tc... - by removing the constructors and destructors for these structs and relying on init lists instead, we allow the compiler to automatically determine how to allocate and deallocate the values and references --- .../src/shared/buffers/ObjvarBuffer.cpp | 18 ++++++++-------- .../src/shared/buffers/ObjvarBuffer.h | 21 +------------------ 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.cpp index c0e0a5bf..49bcd5c6 100755 --- a/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.cpp +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.cpp @@ -63,7 +63,7 @@ bool ObjvarBuffer::load(DB::Session *session,const DB::TagSet &tags, const std:: break; } - IndexKey key(row->object_id.getValue(), row->name_id.getValue()); + IndexKey key = { row->object_id.getValue(), row->name_id.getValue() }; ObjvarValue value; value.m_type=row->type.getValue(); @@ -100,7 +100,7 @@ bool ObjvarBuffer::load(DB::Session *session,const DB::TagSet &tags, const std:: break; } - IndexKey key(row->object_id.getValue(), row->name_id.getValue()); + IndexKey key = { row->object_id.getValue(), row->name_id.getValue() }; ObjvarValue value; value.m_type=row->type.getValue(); @@ -204,7 +204,7 @@ void ObjvarBuffer::getObjvarsForObject(const NetworkId &objectId, std::vectorfirst.m_objectId==objectId); ++i) + for (DataType::const_iterator i= m_data.lower_bound(IndexKey {objectId,0}); (i!=m_data.end()) && (i->first.m_objectId==objectId); ++i) { std::string name; bool foundName = false; @@ -234,7 +234,7 @@ void ObjvarBuffer::getObjvarsForObject(const NetworkId &objectId, std::vectorfirst.m_objectId==objectId); ++i) + for (DataType::const_iterator i= m_overrides.lower_bound(IndexKey {objectId,0}); (i!=m_overrides.end()) && (i->first.m_objectId==objectId); ++i) { std::string name; bool foundName = false; @@ -279,10 +279,10 @@ void ObjvarBuffer::updateObjvars(const NetworkId &objectId, const std::vectorkey); - DataType::iterator row=m_data.find(IndexKey(objectId, nameId)); + DataType::iterator row=m_data.find(IndexKey {objectId, nameId}); if (row==m_data.end()) { - row=m_data.insert(std::make_pair(IndexKey(objectId, nameId),ObjvarValue())).first; + row=m_data.insert(std::make_pair(IndexKey{objectId, nameId},ObjvarValue())).first; if (i->cmd==DynamicVariableList::MapType::Command::ADD || override) row->second.m_inDatabase=false; // new variable else @@ -300,12 +300,12 @@ void ObjvarBuffer::updateObjvars(const NetworkId &objectId, const std::vectorkey); if (nameId != 0) // It's possible to get an ERASE for a packed objvar where the name was never used in the OBJECT_VARIABLES table. We can safely ignore these. { - DataType::iterator row=m_data.find(IndexKey(objectId, nameId)); + DataType::iterator row=m_data.find(IndexKey {objectId, nameId}); if (row==m_data.end()) { if (i->value.getPosition() == -1 || override) { - row=m_data.insert(std::make_pair(IndexKey(objectId, nameId),ObjvarValue())).first; + row=m_data.insert(std::make_pair(IndexKey {objectId, nameId},ObjvarValue())).first; row->second.m_inDatabase=true; // deleting existing variable } // else it was a packed objvar, and no update is necessary @@ -329,7 +329,7 @@ void ObjvarBuffer::updateObjvars(const NetworkId &objectId, const std::vectorfirst.m_objectId==object) { i = m_data.erase(i); diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.h index f834649b..42bc45ea 100755 --- a/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.h +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.h @@ -57,13 +57,9 @@ public: private: struct IndexKey { - NetworkId m_objectId; + const NetworkId &m_objectId; int m_nameId; - IndexKey(const NetworkId &objectId, int nameId); - ~IndexKey(){ - m_nameId = 0; - } bool operator==(const IndexKey &rhs) const; bool operator<(const IndexKey &rhs) const; }; @@ -74,12 +70,6 @@ public: std::string m_value; bool m_detached; bool m_inDatabase; - ~ObjvarValue(){ - m_type = 0; - m_detached = 0; - m_inDatabase = 0; - m_value.clear(); - } }; typedef std::map DataType; @@ -92,7 +82,6 @@ public: // typedef std::map > LoadIndexType; // LoadIndexType m_loadIndex; - private: ObjvarBuffer(); //disable ObjvarBuffer(const ObjvarBuffer&); //disable @@ -101,14 +90,6 @@ public: // ====================================================================== -inline ObjvarBuffer::IndexKey::IndexKey(const NetworkId &objectId, int nameId) : - m_objectId(objectId), - m_nameId(nameId) -{ -} - -// ---------------------------------------------------------------------- - inline bool ObjvarBuffer::IndexKey::operator==(const IndexKey &rhs) const { return ((m_objectId == rhs.m_objectId) && (m_nameId == rhs.m_nameId));