mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-16 08:42:23 +00:00
Reduce copying further by adding move constructors and move assignment operators to CellRef structs.
This commit is contained in:
parent
23e7e3c165
commit
19af94b73e
@ -4,10 +4,32 @@
|
|||||||
|
|
||||||
CSMWorld::CellRef::CellRef()
|
CSMWorld::CellRef::CellRef()
|
||||||
{
|
{
|
||||||
|
mId.clear();
|
||||||
|
mCell.clear();
|
||||||
|
mOriginalCell.clear();
|
||||||
|
|
||||||
mRefNum.mIndex = 0;
|
mRefNum.mIndex = 0;
|
||||||
mRefNum.mContentFile = 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
|
std::pair<int, int> CSMWorld::CellRef::getCellIndex() const
|
||||||
{
|
{
|
||||||
const int cellSize = 8192;
|
const int cellSize = 8192;
|
||||||
|
@ -15,6 +15,11 @@ namespace CSMWorld
|
|||||||
std::string mOriginalCell;
|
std::string mOriginalCell;
|
||||||
|
|
||||||
CellRef();
|
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)
|
/// Calculate cell index based on coordinates (x and y)
|
||||||
std::pair<int, int> getCellIndex() const;
|
std::pair<int, int> getCellIndex() const;
|
||||||
|
@ -114,7 +114,7 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
|
|||||||
|
|
||||||
std::unique_ptr<Record<CellRef> > record(new Record<CellRef>);
|
std::unique_ptr<Record<CellRef> > record(new Record<CellRef>);
|
||||||
record->mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
|
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));
|
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)));
|
std::unique_ptr<Record<CellRef> > record(new Record<CellRef>(getRecord(index)));
|
||||||
record->mState = base ? RecordBase::State_BaseOnly : RecordBase::State_Modified;
|
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));
|
setRecord(index, std::move(record));
|
||||||
}
|
}
|
||||||
|
@ -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)
|
bool ESM::operator== (const RefNum& left, const RefNum& right)
|
||||||
{
|
{
|
||||||
return left.mIndex==right.mIndex && left.mContentFile==right.mContentFile;
|
return left.mIndex==right.mIndex && left.mContentFile==right.mContentFile;
|
||||||
|
@ -109,6 +109,15 @@ namespace ESM
|
|||||||
void save (ESMWriter &esm, bool wideRefNum = false, bool inInventory = false, bool isDeleted = false) const;
|
void save (ESMWriter &esm, bool wideRefNum = false, bool inInventory = false, bool isDeleted = false) const;
|
||||||
|
|
||||||
void blank();
|
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);
|
bool operator== (const RefNum& left, const RefNum& right);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user