From ad7fb3d13fc39d28d9b51f7f8e19c9e22a32c677 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sat, 29 Jun 2024 10:31:49 +0200 Subject: [PATCH] Avoid a few copies in mwscript --- apps/openmw/mwscript/controlextensions.cpp | 8 ++++---- components/compiler/extensions.cpp | 16 ++++++++-------- components/compiler/extensions.hpp | 7 +++---- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/apps/openmw/mwscript/controlextensions.cpp b/apps/openmw/mwscript/controlextensions.cpp index a69f2cd571..b9e8f8965a 100644 --- a/apps/openmw/mwscript/controlextensions.cpp +++ b/apps/openmw/mwscript/controlextensions.cpp @@ -25,11 +25,11 @@ namespace MWScript { class OpSetControl : public Interpreter::Opcode0 { - std::string mControl; + std::string_view mControl; bool mEnable; public: - OpSetControl(const std::string& control, bool enable) + OpSetControl(std::string_view control, bool enable) : mControl(control) , mEnable(enable) { @@ -43,10 +43,10 @@ namespace MWScript class OpGetDisabled : public Interpreter::Opcode0 { - std::string mControl; + std::string_view mControl; public: - OpGetDisabled(const std::string& control) + OpGetDisabled(std::string_view control) : mControl(control) { } diff --git a/components/compiler/extensions.cpp b/components/compiler/extensions.cpp index 8431589769..d5d87129d6 100644 --- a/components/compiler/extensions.cpp +++ b/components/compiler/extensions.cpp @@ -51,7 +51,7 @@ namespace Compiler } void Extensions::registerFunction( - const std::string& keyword, ScriptReturn returnType, const ScriptArgs& argumentType, int code, int codeExplicit) + const std::string& keyword, ScriptReturn returnType, ScriptArgs argumentType, int code, int codeExplicit) { Function function; @@ -70,18 +70,18 @@ namespace Compiler int keywordIndex = mNextKeywordIndex--; - mKeywords.insert(std::make_pair(keyword, keywordIndex)); + mKeywords.emplace(keyword, keywordIndex); function.mReturn = returnType; - function.mArguments = argumentType; + function.mArguments = std::move(argumentType); function.mCode = code; function.mCodeExplicit = codeExplicit; - mFunctions.insert(std::make_pair(keywordIndex, function)); + mFunctions.emplace(keywordIndex, std::move(function)); } void Extensions::registerInstruction( - const std::string& keyword, const ScriptArgs& argumentType, int code, int codeExplicit) + const std::string& keyword, ScriptArgs argumentType, int code, int codeExplicit) { Instruction instruction; @@ -100,13 +100,13 @@ namespace Compiler int keywordIndex = mNextKeywordIndex--; - mKeywords.insert(std::make_pair(keyword, keywordIndex)); + mKeywords.emplace(keyword, keywordIndex); - instruction.mArguments = argumentType; + instruction.mArguments = std::move(argumentType); instruction.mCode = code; instruction.mCodeExplicit = codeExplicit; - mInstructions.insert(std::make_pair(keywordIndex, instruction)); + mInstructions.emplace(keywordIndex, std::move(instruction)); } void Extensions::generateFunctionCode(int keyword, std::vector& code, Literals& literals, diff --git a/components/compiler/extensions.hpp b/components/compiler/extensions.hpp index 016a53d725..9e888777e1 100644 --- a/components/compiler/extensions.hpp +++ b/components/compiler/extensions.hpp @@ -80,16 +80,15 @@ namespace Compiler /// \param explicitReference In: has explicit reference; Out: set to false, if /// explicit reference is not available for this instruction. - void registerFunction(const std::string& keyword, ScriptReturn returnType, const ScriptArgs& argumentType, - int code, int codeExplicit = -1); + void registerFunction(const std::string& keyword, ScriptReturn returnType, ScriptArgs argumentType, int code, + int codeExplicit = -1); ///< Register a custom function /// - keyword must be all lower case. /// - keyword must be unique /// - if explicit references are not supported, segment5codeExplicit must be set to -1 /// \note Currently only segment 3 and segment 5 opcodes are supported. - void registerInstruction( - const std::string& keyword, const ScriptArgs& argumentType, int code, int codeExplicit = -1); + void registerInstruction(const std::string& keyword, ScriptArgs argumentType, int code, int codeExplicit = -1); ///< Register a custom instruction /// - keyword must be all lower case. /// - keyword must be unique