1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-30 19:15:41 +00:00

Merge branch 'copycompiler' into 'master'

Avoid a few copies in mwscript

See merge request OpenMW/openmw!4215
This commit is contained in:
psi29a 2024-07-01 07:43:53 +00:00
commit 045bccb3e9
3 changed files with 14 additions and 14 deletions

View file

@ -25,11 +25,11 @@ namespace MWScript
{ {
class OpSetControl : public Interpreter::Opcode0 class OpSetControl : public Interpreter::Opcode0
{ {
std::string mControl; std::string_view mControl;
bool mEnable; bool mEnable;
public: public:
OpSetControl(const std::string& control, bool enable) OpSetControl(std::string_view control, bool enable)
: mControl(control) : mControl(control)
, mEnable(enable) , mEnable(enable)
{ {
@ -43,10 +43,10 @@ namespace MWScript
class OpGetDisabled : public Interpreter::Opcode0 class OpGetDisabled : public Interpreter::Opcode0
{ {
std::string mControl; std::string_view mControl;
public: public:
OpGetDisabled(const std::string& control) OpGetDisabled(std::string_view control)
: mControl(control) : mControl(control)
{ {
} }

View file

@ -51,11 +51,11 @@ namespace Compiler
} }
void Extensions::registerFunction( void Extensions::registerFunction(
const std::string& keyword, ScriptReturn returnType, const ScriptArgs& argumentType, int code, int codeExplicit) std::string_view keyword, ScriptReturn returnType, std::string_view argumentType, int code, int codeExplicit)
{ {
Function function; Function function;
if (argumentType.find('/') == std::string::npos) if (argumentType.find('/') == std::string_view::npos)
{ {
function.mSegment = 5; function.mSegment = 5;
assert(code >= 33554432 && code <= 67108863); assert(code >= 33554432 && code <= 67108863);
@ -70,22 +70,22 @@ namespace Compiler
int keywordIndex = mNextKeywordIndex--; int keywordIndex = mNextKeywordIndex--;
mKeywords.insert(std::make_pair(keyword, keywordIndex)); mKeywords.emplace(keyword, keywordIndex);
function.mReturn = returnType; function.mReturn = returnType;
function.mArguments = argumentType; function.mArguments = argumentType;
function.mCode = code; function.mCode = code;
function.mCodeExplicit = codeExplicit; function.mCodeExplicit = codeExplicit;
mFunctions.insert(std::make_pair(keywordIndex, function)); mFunctions.emplace(keywordIndex, std::move(function));
} }
void Extensions::registerInstruction( void Extensions::registerInstruction(
const std::string& keyword, const ScriptArgs& argumentType, int code, int codeExplicit) std::string_view keyword, std::string_view argumentType, int code, int codeExplicit)
{ {
Instruction instruction; Instruction instruction;
if (argumentType.find('/') == std::string::npos) if (argumentType.find('/') == std::string_view::npos)
{ {
instruction.mSegment = 5; instruction.mSegment = 5;
assert(code >= 33554432 && code <= 67108863); assert(code >= 33554432 && code <= 67108863);
@ -100,13 +100,13 @@ namespace Compiler
int keywordIndex = mNextKeywordIndex--; int keywordIndex = mNextKeywordIndex--;
mKeywords.insert(std::make_pair(keyword, keywordIndex)); mKeywords.emplace(keyword, keywordIndex);
instruction.mArguments = argumentType; instruction.mArguments = argumentType;
instruction.mCode = code; instruction.mCode = code;
instruction.mCodeExplicit = codeExplicit; instruction.mCodeExplicit = codeExplicit;
mInstructions.insert(std::make_pair(keywordIndex, instruction)); mInstructions.emplace(keywordIndex, std::move(instruction));
} }
void Extensions::generateFunctionCode(int keyword, std::vector<Interpreter::Type_Code>& code, Literals& literals, void Extensions::generateFunctionCode(int keyword, std::vector<Interpreter::Type_Code>& code, Literals& literals,

View file

@ -80,7 +80,7 @@ namespace Compiler
/// \param explicitReference In: has explicit reference; Out: set to false, if /// \param explicitReference In: has explicit reference; Out: set to false, if
/// explicit reference is not available for this instruction. /// explicit reference is not available for this instruction.
void registerFunction(const std::string& keyword, ScriptReturn returnType, const ScriptArgs& argumentType, void registerFunction(std::string_view keyword, ScriptReturn returnType, std::string_view argumentType,
int code, int codeExplicit = -1); int code, int codeExplicit = -1);
///< Register a custom function ///< Register a custom function
/// - keyword must be all lower case. /// - keyword must be all lower case.
@ -89,7 +89,7 @@ namespace Compiler
/// \note Currently only segment 3 and segment 5 opcodes are supported. /// \note Currently only segment 3 and segment 5 opcodes are supported.
void registerInstruction( void registerInstruction(
const std::string& keyword, const ScriptArgs& argumentType, int code, int codeExplicit = -1); std::string_view keyword, std::string_view argumentType, int code, int codeExplicit = -1);
///< Register a custom instruction ///< Register a custom instruction
/// - keyword must be all lower case. /// - keyword must be all lower case.
/// - keyword must be unique /// - keyword must be unique