Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21015: Fixes rare issue where some nulls may fail a type check against other nulls, improves performance of type comparisons #191

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions src/Amalgam/interpreter/InterpreterOpcodesLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_TYPE_EQUALS(EvaluableNode

bool processed_first_value = false;
EvaluableNodeReference to_match = EvaluableNodeReference::Null();
EvaluableNodeType to_match_type = ENT_NULL;

#ifdef MULTITHREAD_SUPPORT
std::vector<EvaluableNodeReference> interpreted_nodes;
Expand All @@ -491,6 +492,8 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_TYPE_EQUALS(EvaluableNode
if(!processed_first_value)
{
to_match = cur;
if(to_match != nullptr)
to_match_type = to_match->GetType();
processed_first_value = true;
continue;
}
Expand All @@ -499,10 +502,6 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_TYPE_EQUALS(EvaluableNode
if(cur != nullptr)
cur_type = cur->GetType();

EvaluableNodeType to_match_type = ENT_NULL;
if(to_match != nullptr)
to_match_type = to_match->GetType();

if(cur_type != to_match_type)
return ReuseOrAllocOneOfReturn(to_match, cur, false, immediate_result);

Expand All @@ -523,6 +522,8 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_TYPE_EQUALS(EvaluableNode
if(!processed_first_value)
{
to_match = cur;
if(to_match != nullptr)
to_match_type = to_match->GetType();
node_stack.PushEvaluableNode(to_match);
processed_first_value = true;
continue;
Expand All @@ -531,10 +532,6 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_TYPE_EQUALS(EvaluableNode
EvaluableNodeType cur_type = ENT_NULL;
if(cur != nullptr)
cur_type = cur->GetType();

EvaluableNodeType to_match_type = ENT_NULL;
if(to_match != nullptr)
to_match_type = to_match->GetType();

if(cur_type != to_match_type)
return ReuseOrAllocOneOfReturn(to_match, cur, false, immediate_result);
Expand All @@ -552,6 +549,23 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_TYPE_NEQUALS(EvaluableNode
if(ocn.size() == 0)
return EvaluableNodeReference::Null();

//special (faster) case for comparing two
if(ocn.size() == 2)
{
EvaluableNodeReference a = InterpretNodeForImmediateUse(ocn[0]);
EvaluableNodeType a_type = ENT_NULL;
if(a != nullptr)
a_type = a->GetType();

auto node_stack = CreateInterpreterNodeStackStateSaver(a);
EvaluableNodeReference b = InterpretNodeForImmediateUse(ocn[1]);
EvaluableNodeType b_type = ENT_NULL;
if(b != nullptr)
b_type = b->GetType();

return ReuseOrAllocOneOfReturn(a, b, a_type != b_type, immediate_result);
}

std::vector<EvaluableNodeReference> values(ocn.size());

auto node_stack = CreateInterpreterNodeStackStateSaver();
Expand All @@ -572,8 +586,16 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_TYPE_NEQUALS(EvaluableNode
EvaluableNode *cur1 = values[i];
EvaluableNode *cur2 = values[j];

EvaluableNodeType cur1_type = ENT_NULL;
if(cur1 != nullptr)
cur1_type = cur1->GetType();

EvaluableNodeType cur2_type = ENT_NULL;
if(cur2 != nullptr)
cur2_type = cur2->GetType();

//if they're equal, then it fails
if((cur1 == nullptr && cur2 == nullptr) || (cur1 != nullptr && cur2 != nullptr && cur1->GetType() == cur2->GetType()))
if(cur1_type == cur2_type)
{
all_not_equal = false;

Expand Down
Loading