diff options
| author | Léo Lam <leo@leolam.fr> | 2021-01-05 22:28:50 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-05 16:28:50 -0500 |
| commit | 978dcbcb5a9cb68d558de132c0661f6141887e5d (patch) | |
| tree | a5979f922825b85864e08cef6c79f742c1b4cd91 /ZAPD/ZAnimation.cpp | |
| parent | 4ea37af45af670e65547a35c49a2288ef2a63245 (diff) | |
Avoid unnecessary copies (#46)
Pass some parameters by reference to avoid unnecessary copies.
When the parameter is intended to be copied into a member variable,
pass it by value and move it into the member instead.
This doesn't fix every occurrence of the issue but this diff is already
getting big so let's stop here for the moment.
Diffstat (limited to 'ZAPD/ZAnimation.cpp')
| -rw-r--r-- | ZAPD/ZAnimation.cpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/ZAPD/ZAnimation.cpp b/ZAPD/ZAnimation.cpp index 91bd7ee..1d8ae04 100644 --- a/ZAPD/ZAnimation.cpp +++ b/ZAPD/ZAnimation.cpp @@ -1,4 +1,5 @@ #include "ZAnimation.h" +#include <utility> #include "ZFile.h" #include "BitConverter.h" #include "StringHelper.h" @@ -15,13 +16,13 @@ ZAnimation::ZAnimation() : ZResource() void ZAnimation::ParseRawData() { - uint8_t* data = rawData.data(); + const uint8_t* data = rawData.data(); // Read the header frameCount = BitConverter::ToInt16BE(data, rawDataIndex + 0); } -void ZAnimation::Save(string outFolder) +void ZAnimation::Save(const std::string& outFolder) { if (Globals::Instance->testMode) { @@ -40,7 +41,7 @@ void ZAnimation::ParseXML(tinyxml2::XMLElement* reader) name = reader->Attribute("Name"); } -string ZAnimation::GetSourceOutputCode(string prefix) +string ZAnimation::GetSourceOutputCode(const std::string& prefix) { return ""; } @@ -52,7 +53,7 @@ ZNormalAnimation::ZNormalAnimation() : ZAnimation() limit = 0; } -std::string ZNormalAnimation::GetSourceOutputCode(std::string prefix) +std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix) { if (parent != nullptr) { @@ -99,10 +100,10 @@ int ZNormalAnimation::GetRawDataSize() return 16; } -ZNormalAnimation* ZNormalAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, std::string nRelPath) +ZNormalAnimation* ZNormalAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, const std::string& nRelPath) { ZNormalAnimation* anim = new ZNormalAnimation(); - anim->rawData = nRawData; + anim->rawData = std::move(nRawData); anim->rawDataIndex = rawDataIndex; anim->ParseXML(reader); anim->ParseRawData(); @@ -114,7 +115,7 @@ void ZNormalAnimation::ParseRawData() { ZAnimation::ParseRawData(); - uint8_t* data = rawData.data(); + const uint8_t* data = rawData.data(); rotationValuesSeg = BitConverter::ToInt32BE(data, rawDataIndex + 4) & 0x00FFFFFF; rotationIndicesSeg = BitConverter::ToInt32BE(data, rawDataIndex + 8) & 0x00FFFFFF; @@ -144,7 +145,7 @@ ZLinkAnimation::ZLinkAnimation() : ZAnimation() segmentAddress = 0; } -std::string ZLinkAnimation::GetSourceOutputCode(std::string prefix) +std::string ZLinkAnimation::GetSourceOutputCode(const std::string& prefix) { if (parent != nullptr) { @@ -162,10 +163,10 @@ int ZLinkAnimation::GetRawDataSize() return 8; } -ZLinkAnimation* ZLinkAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, std::string nRelPath) +ZLinkAnimation* ZLinkAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, const std::string& nRelPath) { ZLinkAnimation* anim = new ZLinkAnimation(); - anim->rawData = nRawData; + anim->rawData = std::move(nRawData); anim->rawDataIndex = rawDataIndex; anim->ParseXML(reader); anim->ParseRawData(); @@ -177,7 +178,7 @@ void ZLinkAnimation::ParseRawData() { ZAnimation::ParseRawData(); - uint8_t* data = rawData.data(); + const uint8_t* data = rawData.data(); //segmentAddress = SEG2FILESPACE(BitConverter::ToInt32BE(data, rawDataIndex + 4)); segmentAddress = (BitConverter::ToInt32BE(data, rawDataIndex + 4)); |
