@@ -557,57 +557,51 @@ class GameInstructionConst : public game_instruction {
557557 r_string get_name () const override { return " " sv; }
558558};
559559
560- void addScopeInstruction (ref<compact_array< ref<game_instruction> >>& bodyCode, const r_string& scriptName) {
560+ void addScopeInstruction (auto_array< ref<game_instruction>>& bodyCode, const r_string& scriptName) {
561561#ifndef __linux__
562562#ifndef _WIN64
563563#error "no x64 hash codes yet"
564564#endif
565565#endif
566- if (! bodyCode) return ;
566+ if (bodyCode. empty () ) return ;
567567
568- auto lt = typeid (bodyCode-> data ()[0 ]).hash_code ();
568+ auto lt = typeid (bodyCode. data ()[0 ]).hash_code ();
569569 auto rt = typeid (GameInstructionProfileScopeStart).hash_code ();
570570
571571 if (lt == rt) return ;
572- if (bodyCode-> size () < 4 ) return ;
572+ if (bodyCode. size () < 4 ) return ;
573573
574574
575- auto & funcPath = bodyCode-> front ()->sdp .sourcefile ;
575+ auto & funcPath = bodyCode. front ()->sdp .sourcefile ;
576576 // r_string src = getScriptFromFirstLine(bodyCode->instructions->front()->sdp, false);
577577
578578
579579
580580 // Insert instruction to set _x
581581 ref<GameInstructionProfileScopeStart> curElInstruction = rv_allocator<GameInstructionProfileScopeStart>::create_single (scriptName);
582- curElInstruction->sdp = bodyCode-> front ()->sdp ;
582+ curElInstruction->sdp = bodyCode. front ()->sdp ;
583583 curElInstruction->scopeInfo = GProfilerAdapter->createScope (curElInstruction->name ,
584584 funcPath.empty () ? curElInstruction->name : funcPath,
585585 curElInstruction->sdp .sourceline );
586586 // if (scriptName == "<unknown>")
587587 // curElInstruction->eventDescription->source = src;
588588
589-
590- auto oldInstructions = bodyCode;
591- ref<compact_array<ref<game_instruction>>> newInstr = compact_array<ref<game_instruction>>::create (*oldInstructions, oldInstructions->size () + 1 );
592-
593- std::copy (oldInstructions->begin (), oldInstructions->begin () + oldInstructions->size (), newInstr->begin () + 1 );
594- newInstr->data ()[0 ] = curElInstruction;
595- bodyCode = newInstr;
596-
589+ // Add instruction at start
590+ bodyCode.insert (bodyCode.begin (), curElInstruction);
597591
598592#ifdef __linux__
599593 static const size_t ConstTypeIDHash = 600831349 ;
600594#else
601595 static const size_t ConstTypeIDHash = 0x0a56f03038a03360ull ;
602596#endif
603- for (auto & it : * bodyCode) {
597+ for (auto & it : bodyCode) {
604598
605599 auto instC = dynamic_cast <GameInstructionProfileScopeStart*>(it.get ());
606600 if (instC) {
607601 break ;
608602 }
609603
610- auto typeHash = typeid (* it.get ()).hash_code ();
604+ auto typeHash = typeid (it.get ()).hash_code ();
611605
612606 // linux
613607 // auto typeN = typeid(*it.get()).name();
@@ -620,7 +614,7 @@ void addScopeInstruction(ref<compact_array<ref<game_instruction>>>& bodyCode, co
620614 if (inst->value .type_enum () != game_data_type::CODE) continue ;
621615
622616 auto bodyCodeNext = static_cast <game_data_code*>(inst->value .data .get ());
623- if (bodyCodeNext->instructions && bodyCodeNext-> instructions -> size () > 20 )
617+ if (bodyCodeNext->instructions . size () > 20 )
624618 addScopeInstruction (bodyCodeNext->instructions , scriptName);
625619 }
626620}
@@ -655,7 +649,7 @@ game_value compileRedirect2(game_state& state, game_value_parameter message) {
655649
656650 auto comp = sqf::compile (str);
657651 auto bodyCode = static_cast <game_data_code*>(comp.data .get ());
658- if (! bodyCode->instructions ) {
652+ if (bodyCode->instructions . empty () ) {
659653 GProfilerAdapter->leaveScope (tempData);
660654 return comp;
661655 }
@@ -669,13 +663,13 @@ game_value compileRedirect2(game_state& state, game_value_parameter message) {
669663
670664 GProfilerAdapter->leaveScope (tempData);
671665
672- auto & funcPath = bodyCode->instructions -> front ()->sdp .sourcefile ;
666+ auto & funcPath = bodyCode->instructions . front ()->sdp .sourcefile ;
673667 // #TODO pass instructions to getScriptName and check if there is a "scriptName" or "scopeName" unary command call
674668 r_string scriptName (getScriptName (str, funcPath, 32 ));
675669
676670 // if (scriptName.empty()) scriptName = "<unknown>";
677671
678- if (bodyCode->instructions && bodyCode-> instructions -> size () > 4 && !scriptName.empty ())// && scriptName != "<unknown>"
672+ if (bodyCode->instructions . size () > 4 && !scriptName.empty ())// && scriptName != "<unknown>"
679673 addScopeInstruction (bodyCode->instructions , scriptName);
680674
681675 return comp;
@@ -694,7 +688,7 @@ game_value compileRedirectFinal(game_state& state, game_value_parameter message)
694688
695689 auto comp = sqf::compile_final (str);
696690 auto bodyCode = static_cast <game_data_code*>(comp.data .get ());
697- if (! bodyCode->instructions ) {
691+ if (bodyCode->instructions . empty () ) {
698692 GProfilerAdapter->leaveScope (tempData);
699693 return comp;
700694 }
@@ -708,14 +702,14 @@ game_value compileRedirectFinal(game_state& state, game_value_parameter message)
708702
709703 GProfilerAdapter->leaveScope (tempData);
710704
711- auto & funcPath = bodyCode->instructions -> front ()->sdp .sourcefile ;
705+ auto & funcPath = bodyCode->instructions . front ()->sdp .sourcefile ;
712706
713707 auto scriptName = tryGetNameFromInitFunctions (state);
714708 if (!scriptName) scriptName = tryGetNameFromCBACompile (state);
715709 if (!scriptName) scriptName = getScriptName (str, funcPath, 32 );
716710 // if (scriptName.empty()) scriptName = "<unknown>";
717711
718- if (bodyCode->instructions && bodyCode-> instructions -> size () > 4 && scriptName && !scriptName->empty ())// && scriptName != "<unknown>"
712+ if (bodyCode->instructions . size () > 4 && scriptName && !scriptName->empty ())// && scriptName != "<unknown>"
719713 addScopeInstruction (bodyCode->instructions , *scriptName);
720714
721715 return comp;
0 commit comments