minor cleanup to ExprOpUpdate::eval()

Change-Id: I79260638dbd6b7929154f4754257aec423188358
This commit is contained in:
Qyriad 2024-07-04 09:36:03 -06:00
parent 2fc9c64131
commit d31a814266

View file

@ -2003,35 +2003,37 @@ void ExprOpImpl::eval(EvalState & state, Env & env, Value & v)
void ExprOpUpdate::eval(EvalState & state, Env & env, Value & v)
{
Value v1, v2;
state.evalAttrs(env, *e1, v1, pos, "in the left operand of the update (//) operator");
state.evalAttrs(env, *e2, v2, pos, "in the right operand of the update (//) operator");
Value lhsVal;
Value rhsVal;
state.evalAttrs(env, *e1, lhsVal, pos, "in the left operand of the update (//) operator");
state.evalAttrs(env, *e2, rhsVal, pos, "in the right operand of the update (//) operator");
state.nrOpUpdates++;
if (v1.attrs->size() == 0) { v = v2; return; }
if (v2.attrs->size() == 0) { v = v1; return; }
if (lhsVal.attrs->size() == 0) { v = rhsVal; return; }
if (rhsVal.attrs->size() == 0) { v = lhsVal; return; }
auto attrs = state.buildBindings(v1.attrs->size() + v2.attrs->size());
auto attrs = state.buildBindings(lhsVal.attrs->size() + rhsVal.attrs->size());
/* Merge the sets, preferring values from the second set. Make
sure to keep the resulting vector in sorted order. */
Bindings::iterator i = v1.attrs->begin();
Bindings::iterator j = v2.attrs->begin();
Bindings::iterator lhsIt = lhsVal.attrs->begin();
Bindings::iterator rhsIt = rhsVal.attrs->begin();
while (i != v1.attrs->end() && j != v2.attrs->end()) {
if (i->name == j->name) {
attrs.insert(*j);
++i; ++j;
while (lhsIt != lhsVal.attrs->end() && rhsIt != rhsVal.attrs->end()) {
if (lhsIt->name == rhsIt->name) {
attrs.insert(*rhsIt);
++lhsIt;
++rhsIt;
} else if (lhsIt->name < rhsIt->name) {
attrs.insert(*lhsIt++);
} else {
attrs.insert(*rhsIt++);
}
else if (i->name < j->name)
attrs.insert(*i++);
else
attrs.insert(*j++);
}
while (i != v1.attrs->end()) attrs.insert(*i++);
while (j != v2.attrs->end()) attrs.insert(*j++);
while (lhsIt != lhsVal.attrs->end()) attrs.insert(*lhsIt++);
while (rhsIt != rhsVal.attrs->end()) attrs.insert(*rhsIt++);
v.mkAttrs(attrs.alreadySorted());