Skip to content

Commit f225d8b

Browse files
pcaspersGitlab CI
authored andcommitted
Merge branch 'feature/QPR-13803' into 'master'
QPR-13803 avoid some copies Closes QPR-13803 See merge request qs/oreplus!3183
1 parent 43390f4 commit f225d8b

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

OREData/ored/scripting/scriptengine.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class ASTRunner : public AcyclicVisitor,
149149
auto arg = value.pop();
150150
QL_REQUIRE(arg.which() == ValueTypeWhich::Number,
151151
"array subscript must be of type NUMBER, got " << valueTypeLabels.at(arg.which()));
152-
RandomVariable i = boost::get<RandomVariable>(arg);
152+
RandomVariable& i = boost::get<RandomVariable>(arg);
153153
QL_REQUIRE(i.deterministic(), "array subscript must be deterministic");
154154
long il = std::lround(i.at(0));
155155
QL_REQUIRE(static_cast<long>(v.cachedVector->size()) >= il && il >= 1,
@@ -195,7 +195,7 @@ class ASTRunner : public AcyclicVisitor,
195195
checkpoint(*arg);
196196
auto size = value.pop();
197197
QL_REQUIRE(size.which() == ValueTypeWhich::Number, "expected NUMBER for array size definition");
198-
RandomVariable arraySize = boost::get<RandomVariable>(size);
198+
RandomVariable& arraySize = boost::get<RandomVariable>(size);
199199
QL_REQUIRE(arraySize.deterministic(), "array size definition requires deterministic argument");
200200
long arraySizeL = std::lround(arraySize.at(0));
201201
QL_REQUIRE(arraySizeL >= 0, "expected non-negative array size, got " << arraySizeL);
@@ -258,7 +258,7 @@ class ASTRunner : public AcyclicVisitor,
258258
auto left = value.pop();
259259
checkpoint(n);
260260
QL_REQUIRE(left.which() == ValueTypeWhich::Filter, "expected condition");
261-
Filter l = boost::get<Filter>(left);
261+
Filter& l = boost::get<Filter>(left);
262262
if (l.deterministic() && !l[0]) {
263263
// short cut if first expression is already false
264264
value.push(Filter(l.size(), false));
@@ -278,7 +278,7 @@ class ASTRunner : public AcyclicVisitor,
278278
auto left = value.pop();
279279
checkpoint(n);
280280
QL_REQUIRE(left.which() == ValueTypeWhich::Filter, "expected condition");
281-
Filter l = boost::get<Filter>(left);
281+
Filter& l = boost::get<Filter>(left);
282282
if (l.deterministic() && l[0]) {
283283
// short cut if first expression is already true
284284
value.push(Filter(l.size(), true));
@@ -430,7 +430,7 @@ class ASTRunner : public AcyclicVisitor,
430430
checkpoint(n);
431431
QL_REQUIRE(if_.which() == ValueTypeWhich::Filter,
432432
"IF must be followed by a boolean, got " << valueTypeLabels.at(if_.which()));
433-
Filter cond = boost::get<Filter>(if_);
433+
Filter& cond = boost::get<Filter>(if_);
434434
TRACE("if( " << cond << " )", n);
435435
Filter baseFilter = filter.top();
436436
Filter currentFilter = baseFilter && cond;
@@ -473,9 +473,9 @@ class ASTRunner : public AcyclicVisitor,
473473
"loop bounds and step must be of type NUMBER, got " << valueTypeLabels.at(left.which()) << ", "
474474
<< valueTypeLabels.at(right.which()) << ", "
475475
<< valueTypeLabels.at(step.which()));
476-
RandomVariable a = boost::get<RandomVariable>(left);
477-
RandomVariable b = boost::get<RandomVariable>(right);
478-
RandomVariable s = boost::get<RandomVariable>(step);
476+
RandomVariable& a = boost::get<RandomVariable>(left);
477+
RandomVariable& b = boost::get<RandomVariable>(right);
478+
RandomVariable& s = boost::get<RandomVariable>(step);
479479
QL_REQUIRE(a.deterministic(), "first loop bound must be deterministic");
480480
QL_REQUIRE(b.deterministic(), "second loop bound must be deterministic");
481481
QL_REQUIRE(s.deterministic(), "loop step must be deterministic");
@@ -747,12 +747,12 @@ class ASTRunner : public AcyclicVisitor,
747747
QL_REQUIRE(forward.which() == ValueTypeWhich::Number, "forward must be NUMBER");
748748
QL_REQUIRE(forward.which() == ValueTypeWhich::Number, "impliedvol must be NUMBER");
749749

750-
RandomVariable omega = boost::get<RandomVariable>(callput);
750+
RandomVariable& omega = boost::get<RandomVariable>(callput);
751751
Date obs = boost::get<EventVec>(obsdate).value;
752752
Date expiry = boost::get<EventVec>(expirydate).value;
753-
RandomVariable k = boost::get<RandomVariable>(strike);
754-
RandomVariable f = boost::get<RandomVariable>(forward);
755-
RandomVariable v = boost::get<RandomVariable>(impliedvol);
753+
RandomVariable& k = boost::get<RandomVariable>(strike);
754+
RandomVariable& f = boost::get<RandomVariable>(forward);
755+
RandomVariable& v = boost::get<RandomVariable>(impliedvol);
756756

757757
QL_REQUIRE(model_, "model is null");
758758

@@ -807,7 +807,7 @@ class ASTRunner : public AcyclicVisitor,
807807
pn.args[4]->accept(*this);
808808
auto s = value.pop();
809809
QL_REQUIRE(s.which() == ValueTypeWhich::Number, "legno must be NUMBER");
810-
RandomVariable sv = boost::get<RandomVariable>(s);
810+
RandomVariable& sv = boost::get<RandomVariable>(s);
811811
sv.updateDeterministic();
812812
QL_REQUIRE(sv.deterministic(), "legno must be deterministic");
813813
legno = std::lround(sv.at(0));
@@ -821,7 +821,7 @@ class ASTRunner : public AcyclicVisitor,
821821
pn.args[6]->accept(*this);
822822
auto s = value.pop();
823823
QL_REQUIRE(s.which() == ValueTypeWhich::Number, "slot must be NUMBER");
824-
RandomVariable sv = boost::get<RandomVariable>(s);
824+
RandomVariable& sv = boost::get<RandomVariable>(s);
825825
sv.updateDeterministic();
826826
QL_REQUIRE(sv.deterministic(), "slot must be deterministic");
827827
slot = std::lround(sv.at(0));
@@ -888,7 +888,7 @@ class ASTRunner : public AcyclicVisitor,
888888
obs = std::max(obs, model_->referenceDate());
889889
QuantLib::ext::optional<long> mem(QuantLib::ext::nullopt);
890890
if (hasMemSlot) {
891-
RandomVariable v = boost::get<RandomVariable>(memSlot);
891+
RandomVariable& v = boost::get<RandomVariable>(memSlot);
892892
QL_REQUIRE(v.deterministic(), "memory slot must be deterministic");
893893
mem = static_cast<long>(v.at(0));
894894
}
@@ -1103,7 +1103,7 @@ class ASTRunner : public AcyclicVisitor,
11031103
std::string und = boost::get<IndexVec>(underlying).value;
11041104
Date obs1 = boost::get<EventVec>(obsdate1).value;
11051105
Date obs2 = boost::get<EventVec>(obsdate2).value;
1106-
RandomVariable barrierValue = boost::get<RandomVariable>(barrier);
1106+
RandomVariable& barrierValue = boost::get<RandomVariable>(barrier);
11071107
if (obs1 > obs2)
11081108
value.push(RandomVariable(model_->size(), 0.0));
11091109
else

0 commit comments

Comments
 (0)