1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-12 13:13:27 +00:00

Don't store the type name string in the Ptr

This should get rid of all heap allocations caused by constructing or copying
Ptr objects.
This commit is contained in:
Chris Robinson 2013-08-13 06:42:02 -07:00
parent b6d2888c48
commit 11166a1a17
2 changed files with 5 additions and 3 deletions

View File

@ -5,6 +5,8 @@
#include "containerstore.hpp" #include "containerstore.hpp"
const std::string MWWorld::Ptr::sEmptyString;
ESM::CellRef& MWWorld::Ptr::getCellRef() const ESM::CellRef& MWWorld::Ptr::getCellRef() const
{ {
assert (mCellRef); assert (mCellRef);

View File

@ -11,6 +11,8 @@ namespace MWWorld
class Ptr class Ptr
{ {
static const std::string sEmptyString;
public: public:
typedef MWWorld::CellStore CellStore; typedef MWWorld::CellStore CellStore;
@ -20,7 +22,6 @@ namespace MWWorld
ESM::CellRef *mCellRef; ESM::CellRef *mCellRef;
RefData *mRefData; RefData *mRefData;
CellStore *mCell; CellStore *mCell;
std::string mTypeName;
ContainerStore *mContainerStore; ContainerStore *mContainerStore;
public: public:
@ -34,7 +35,7 @@ namespace MWWorld
const std::string& getTypeName() const const std::string& getTypeName() const
{ {
return mTypeName; return mPtr ? mPtr->mTypeName : sEmptyString;
} }
template<typename T> template<typename T>
@ -45,7 +46,6 @@ namespace MWWorld
mCellRef = &liveCellRef->mRef; mCellRef = &liveCellRef->mRef;
mRefData = &liveCellRef->mData; mRefData = &liveCellRef->mData;
mCell = cell; mCell = cell;
mTypeName = typeid (T).name();
} }
template<typename T> template<typename T>