mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-05-11 13:06:56 +03:00
Reduce copying further by adding move constructors and move assignment operators to CellRef structs.
This commit is contained in:
parent
23e7e3c165
commit
19af94b73e
5 changed files with 99 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue