From d31a81426605cd91cc50c7b0d2a3d39725b5c08b Mon Sep 17 00:00:00 2001 From: Qyriad Date: Thu, 4 Jul 2024 09:36:03 -0600 Subject: [PATCH] minor cleanup to ExprOpUpdate::eval() Change-Id: I79260638dbd6b7929154f4754257aec423188358 --- src/libexpr/eval.cc | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index a6a64a43c..0bbdab3ce 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -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());