Skip to content

Commit d1c4eaa

Browse files
Copilotnunoplopes
andcommitted
Modify parameter class to hold rational by value instead of pointer
Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
1 parent e06d59a commit d1c4eaa

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

src/ast/ast.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,12 @@ Revision History:
4141
// -----------------------------------
4242

4343
parameter::~parameter() {
44-
if (auto p = std::get_if<rational*>(&m_val)) {
45-
dealloc(*p);
46-
}
4744
if (auto p = std::get_if<zstring*>(&m_val)) {
4845
dealloc(*p);
4946
}
5047
}
5148

5249
parameter::parameter(parameter const& other) : m_val(other.m_val) {
53-
if (auto p = std::get_if<rational*>(&m_val)) {
54-
m_val = alloc(rational, **p);
55-
}
5650
if (auto p = std::get_if<zstring*>(&m_val)) {
5751
m_val = alloc(zstring, **p);
5852
}

src/ast/ast.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class parameter {
123123
ast*, // for PARAM_AST
124124
symbol, // for PARAM_SYMBOL
125125
zstring*, // for PARAM_ZSTRING
126-
rational*, // for PARAM_RATIONAL
126+
rational, // for PARAM_RATIONAL
127127
double, // for PARAM_DOUBLE (remark: this is not used in float_decl_plugin)
128128
unsigned // for PARAM_EXTERNAL
129129
> m_val;
@@ -135,8 +135,8 @@ class parameter {
135135
explicit parameter(unsigned val): m_val((int)val) {}
136136
explicit parameter(ast * p): m_val(p) {}
137137
explicit parameter(symbol const & s): m_val(s) {}
138-
explicit parameter(rational const & r): m_val(alloc(rational, r)) {}
139-
explicit parameter(rational && r) : m_val(alloc(rational, std::move(r))) {}
138+
explicit parameter(rational const & r): m_val(r) {}
139+
explicit parameter(rational && r) : m_val(std::move(r)) {}
140140
explicit parameter(zstring const& s): m_val(alloc(zstring, s)) {}
141141
explicit parameter(zstring && s): m_val(alloc(zstring, std::move(s))) {}
142142
explicit parameter(double d): m_val(d) {}
@@ -188,7 +188,7 @@ class parameter {
188188
int get_int() const { SASSERT(is_int()); return std::get<int>(m_val); }
189189
ast * get_ast() const { SASSERT(is_ast()); return std::get<ast*>(m_val); }
190190
symbol get_symbol() const { SASSERT(is_symbol()); return std::get<symbol>(m_val); }
191-
rational const & get_rational() const { SASSERT(is_rational()); return *std::get<rational*>(m_val); }
191+
rational const & get_rational() const { SASSERT(is_rational()); return std::get<rational>(m_val); }
192192
zstring const& get_zstring() const { SASSERT(is_zstring()); return *std::get<zstring*>(m_val); }
193193
double get_double() const { SASSERT(is_double()); return std::get<double>(m_val); }
194194
unsigned get_ext_id() const { SASSERT(is_external()); return std::get<unsigned>(m_val); }

0 commit comments

Comments
 (0)