From 978dcbcb5a9cb68d558de132c0661f6141887e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Tue, 5 Jan 2021 22:28:50 +0100 Subject: 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. --- ZAPD/ZAnimation.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'ZAPD/ZAnimation.cpp') 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 #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 nRawData, int rawDataIndex, std::string nRelPath) +ZNormalAnimation* ZNormalAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, std::vector 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 nRawData, int rawDataIndex, std::string nRelPath) +ZLinkAnimation* ZLinkAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, std::vector 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)); -- cgit v1.2.3