Skip to content

Commit

Permalink
Fix Generator buffer realloc function error and Optimize Performance
Browse files Browse the repository at this point in the history
- Use std::move to insert item for bb_t::links.
- Fix a generator buffer realloc size calc issue.
  • Loading branch information
yyc12345 committed Mar 27, 2023
1 parent 69ed63b commit 1e993c9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions Decorator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class Decorator
//std::set<std::pair<CK_ID,CK_ID>> pset;
std::map<CK_ID, std::vector<pio_pos_t>> pin_chain;
std::map<CK_ID, std::vector<pio_pos_t>> pout_chain;

for (auto&i : pins)
{
std::vector<pio_pos_t> &vp = pin_chain[i] = std::vector<pio_pos_t>();
Expand All @@ -166,7 +167,7 @@ class Decorator
lnk_exp.start = link_endpoint_t{ vp.back().id,vp.back().idx,7 };
lnk_exp.end = last;
last = lnk_exp.start;
mappedb(cb->GetID()).links.push_back(lnk_exp);
mappedb(cb->GetID()).links.push_back(std::move(lnk_exp));
++mappedb(cb->GetID()).n_links;
}
}
Expand All @@ -184,7 +185,7 @@ class Decorator
lnk_exp.end = link_endpoint_t{ vp.back().id,vp.back().idx,8 };
lnk_exp.start = last;
last = lnk_exp.end;
mappedb(cb->GetID()).links.push_back(lnk_exp);
mappedb(cb->GetID()).links.push_back(std::move(lnk_exp));
++mappedb(cb->GetID()).n_links;
}
}
Expand All @@ -209,7 +210,7 @@ class Decorator
link_t lnk; lnk.id = 0; lnk.type = 2; lnk.point_count = 0;
lnk.start = link_endpoint_t{ bb.id,bb.idx,dsrc->GetClassID() == CKCID_PARAMETERLOCAL ? 9 : 8 };
lnk.end=link_endpoint_t{aa.id,aa.idx,aa.idx==-2?10:7};
mappedb(aa.lnk_within).links.push_back(lnk);
mappedb(aa.lnk_within).links.push_back(std::move(lnk));
++mappedb(aa.lnk_within).n_links;
conn = true; break;
}
Expand All @@ -221,7 +222,7 @@ class Decorator
pio_pos_t sshp = GetShortcutParamPos(pinp.lnk_within, dsrc->GetID());
lnk.start = link_endpoint_t{ pinp.lnk_within,sshp.idx,5 };
lnk.end = link_endpoint_t{ pinp.id,pinp.idx,pinp.idx == -2 ? 10 : 7 };
mappedb(pinp.lnk_within).links.push_back(lnk);
mappedb(pinp.lnk_within).links.push_back(std::move(lnk));
++mappedb(pinp.lnk_within).n_links;
}
}
Expand All @@ -240,7 +241,7 @@ class Decorator
link_t lnk; lnk.id = 0; lnk.type = 2; lnk.point_count = 0;
lnk.start = link_endpoint_t{ bb.id,bb.idx,7 };
lnk.end = link_endpoint_t{ aa.id,aa.idx,aa.idx == -2 ? 10 : 7 };
mappedb(aa.lnk_within).links.push_back(lnk);
mappedb(aa.lnk_within).links.push_back(std::move(lnk));
++mappedb(aa.lnk_within).n_links;
conn = true; break;
}
Expand Down Expand Up @@ -268,7 +269,7 @@ class Decorator
link_t lnk; lnk.id = 0; lnk.type = 2; lnk.point_count = 0;
lnk.start = link_endpoint_t{ aa.id,aa.idx,8 };
lnk.end = dendp;
mappedb(aa.lnk_within).links.push_back(lnk);
mappedb(aa.lnk_within).links.push_back(std::move(lnk));
++mappedb(aa.lnk_within).n_links;
conn = true; break;
}
Expand All @@ -280,7 +281,7 @@ class Decorator
pio_pos_t sshp = GetShortcutParamPos(ssp.lnk_within, dest->GetID());
lnk.start = link_endpoint_t{ ssp.id,ssp.idx,8 };
lnk.end = link_endpoint_t{ sshp.id,sshp.idx,5 };
mappedb(ssp.lnk_within).links.push_back(lnk);
mappedb(ssp.lnk_within).links.push_back(std::move(lnk));
++mappedb(ssp.lnk_within).n_links;
}
else ctx->OutputToConsoleEx("pout: can't connect %d <-> %d, dest type is %d", po->GetID(), dest->GetID(), dest->GetClassID());
Expand Down Expand Up @@ -631,7 +632,7 @@ class Decorator
lnk.end.index = blink->GetOutBehaviorIO()->GetOwner()->GetOutputPosition(blink->GetOutBehaviorIO());
lnk.end.type = 13;
}
bb.links.push_back(lnk);
bb.links.push_back(std::move(lnk));
}
for (int i = 0, c = beh->GetParameterOperationCount(); i<c; ++i)
{
Expand Down Expand Up @@ -659,6 +660,7 @@ class Decorator
opmap.clear();
pins.clear();
pouts.clear();

std::queue<std::pair<CKBehavior*, int>> bq;
bq.push(std::make_pair(beh, 0));
while (!bq.empty())
Expand Down
2 changes: 1 addition & 1 deletion Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Generator
size_t needed = this->genbuffer_currsor + size_in_char;
if (needed > this->genbuffer_length) {
// if ordered buffer too low, allocated 512 DWORD directly
needed = std::max(needed, 1024u * sizeof(DWORD));
needed = this->genbuffer_currsor + std::max(size_in_char, 1024u * sizeof(DWORD));

// create new buffer
char* newbuf = new char[needed];
Expand Down
2 changes: 1 addition & 1 deletion VirtoolsScriptDeobfuscation.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(VIRTOOLS_INCLUDE_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
Expand All @@ -71,6 +70,7 @@
<PrecompiledHeaderFile>precomp.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<LanguageStandard>stdcpp17</LanguageStandard>
<Optimization>Disabled</Optimization>
</ClCompile>
<Link>
<AdditionalDependencies>ck2.lib;vxmath.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down

0 comments on commit 1e993c9

Please sign in to comment.