1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-04-01 01:36:44 +00:00

Reduce copying further by adding move constructors and move assignment operators to CellRef structs.

This commit is contained in:
cc9cii 2015-12-06 15:20:45 +11:00
parent 23e7e3c165
commit 19af94b73e
5 changed files with 99 additions and 2 deletions

View file

@ -4,10 +4,32 @@
CSMWorld::CellRef::CellRef()
{
mId.clear();
mCell.clear();
mOriginalCell.clear();
mRefNum.mIndex = 0;
mRefNum.mContentFile = 0;
}
CSMWorld::CellRef::CellRef (CSMWorld::CellRef&& other) : ESM::CellRef (other)
{
*this = std::move(other);
}
CSMWorld::CellRef& CSMWorld::CellRef::operator= (CSMWorld::CellRef&& other)
{
if (this != &other)
{
ESM::CellRef::operator= (other);
mId = std::move(other.mId);
mCell = std::move(other.mCell);
mOriginalCell = std::move(other.mOriginalCell);
}
return *this;
}
std::pair<int, int> CSMWorld::CellRef::getCellIndex() const
{
const int cellSize = 8192;

View file

@ -15,6 +15,11 @@ namespace CSMWorld
std::string mOriginalCell;
CellRef();
CellRef(const CellRef&) = default;
CellRef& operator= (const CellRef&) = default;
CellRef (CellRef&& other);
CellRef& operator= (CellRef&& other);
/// Calculate cell index based on coordinates (x and y)
std::pair<int, int> getCellIndex() const;

View file

@ -114,7 +114,7 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
std::unique_ptr<Record<CellRef> > record(new Record<CellRef>);
record->mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
(base ? record->mBase : record->mModified) = ref;
(base ? record->mBase : record->mModified) = std::move(ref);
appendRecord(std::move(record));
@ -129,7 +129,7 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
std::unique_ptr<Record<CellRef> > record(new Record<CellRef>(getRecord(index)));
record->mState = base ? RecordBase::State_BaseOnly : RecordBase::State_Modified;
(base ? record->mBase : record->mModified) = ref;
(base ? record->mBase : record->mModified) = std::move(ref);
setRecord(index, std::move(record));
}

View file

@ -206,6 +206,67 @@ void ESM::CellRef::blank()
}
}
ESM::CellRef::CellRef ()
{
blank();
}
ESM::CellRef::CellRef (const CellRef& other)
: mRefNum(other.mRefNum)
, mRefID(other.mRefID)
, mScale(other.mScale)
, mOwner(other.mOwner)
, mGlobalVariable(other.mGlobalVariable)
, mSoul(other.mSoul)
, mFaction(other.mFaction)
, mFactionRank(other.mFactionRank)
, mChargeInt(other.mChargeInt)
, mEnchantmentCharge(other.mEnchantmentCharge)
, mGoldValue(other.mGoldValue)
, mTeleport(other.mTeleport)
, mDoorDest(other.mDoorDest)
, mDestCell(other.mDestCell)
, mLockLevel(other.mLockLevel)
, mKey(other.mKey)
, mTrap(other.mTrap)
, mReferenceBlocked(other.mReferenceBlocked)
, mPos(other.mPos)
{
}
ESM::CellRef::CellRef (CellRef&& other)
{
*this = std::move(other);
}
ESM::CellRef& ESM::CellRef::operator= (CellRef&& other)
{
if (this != &other)
{
mRefNum = other.mRefNum; // RefNum
mRefID = std::move(other.mRefID);
mScale = other.mScale;
mOwner = std::move(other.mOwner);
mGlobalVariable = std::move(other.mGlobalVariable);
mSoul = std::move(other.mSoul);
mFaction = std::move(other.mFaction);
mFactionRank = other.mFactionRank;
mChargeInt = other.mChargeInt;
mEnchantmentCharge = other.mEnchantmentCharge;
mGoldValue = other.mGoldValue;
mTeleport = other.mTeleport;
mDoorDest = other.mDoorDest; // Position
mDestCell = std::move(other.mDestCell);
mLockLevel = other.mLockLevel;
mKey = std::move(other.mKey);
mTrap = std::move(other.mTrap);
mReferenceBlocked = other.mReferenceBlocked;
mPos = other.mPos; // Position
}
return *this;
}
bool ESM::operator== (const RefNum& left, const RefNum& right)
{
return left.mIndex==right.mIndex && left.mContentFile==right.mContentFile;

View file

@ -109,6 +109,15 @@ namespace ESM
void save (ESMWriter &esm, bool wideRefNum = false, bool inInventory = false, bool isDeleted = false) const;
void blank();
CellRef();
~CellRef() = default;
CellRef(const CellRef&);
CellRef& operator=(const CellRef&) = default;
CellRef (CellRef&& other);
CellRef& operator=(CellRef&& other);
};
bool operator== (const RefNum& left, const RefNum& right);