forked from lix-project/lix
minor cleanup to ExprOpUpdate::eval()
Change-Id: I79260638dbd6b7929154f4754257aec423188358
This commit is contained in:
parent
2fc9c64131
commit
d31a814266
|
@ -2003,35 +2003,37 @@ void ExprOpImpl::eval(EvalState & state, Env & env, Value & v)
|
||||||
|
|
||||||
void ExprOpUpdate::eval(EvalState & state, Env & env, Value & v)
|
void ExprOpUpdate::eval(EvalState & state, Env & env, Value & v)
|
||||||
{
|
{
|
||||||
Value v1, v2;
|
Value lhsVal;
|
||||||
state.evalAttrs(env, *e1, v1, pos, "in the left operand of the update (//) operator");
|
Value rhsVal;
|
||||||
state.evalAttrs(env, *e2, v2, pos, "in the right operand of the update (//) operator");
|
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++;
|
state.nrOpUpdates++;
|
||||||
|
|
||||||
if (v1.attrs->size() == 0) { v = v2; return; }
|
if (lhsVal.attrs->size() == 0) { v = rhsVal; return; }
|
||||||
if (v2.attrs->size() == 0) { v = v1; 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
|
/* Merge the sets, preferring values from the second set. Make
|
||||||
sure to keep the resulting vector in sorted order. */
|
sure to keep the resulting vector in sorted order. */
|
||||||
Bindings::iterator i = v1.attrs->begin();
|
Bindings::iterator lhsIt = lhsVal.attrs->begin();
|
||||||
Bindings::iterator j = v2.attrs->begin();
|
Bindings::iterator rhsIt = rhsVal.attrs->begin();
|
||||||
|
|
||||||
while (i != v1.attrs->end() && j != v2.attrs->end()) {
|
while (lhsIt != lhsVal.attrs->end() && rhsIt != rhsVal.attrs->end()) {
|
||||||
if (i->name == j->name) {
|
if (lhsIt->name == rhsIt->name) {
|
||||||
attrs.insert(*j);
|
attrs.insert(*rhsIt);
|
||||||
++i; ++j;
|
++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 (lhsIt != lhsVal.attrs->end()) attrs.insert(*lhsIt++);
|
||||||
while (j != v2.attrs->end()) attrs.insert(*j++);
|
while (rhsIt != rhsVal.attrs->end()) attrs.insert(*rhsIt++);
|
||||||
|
|
||||||
v.mkAttrs(attrs.alreadySorted());
|
v.mkAttrs(attrs.alreadySorted());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue