Skip to content

Commit 2e25340

Browse files
committed
Reset state info in copy CTOR
Refactor reset code
1 parent cc957e5 commit 2e25340

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

tinyexpr.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,20 +2273,7 @@ te_expr* te_parser::te_compile(const std::string_view expression, std::set<te_va
22732273
//--------------------------------------------------
22742274
bool te_parser::compile(const std::string_view expression)
22752275
{
2276-
// reset everything from previous call
2277-
m_errorPos = te_parser::npos;
2278-
m_lastErrorMessage.clear();
2279-
m_result = te_nan;
2280-
m_parseSuccess = false;
2281-
te_free(m_compiledExpression);
2282-
m_compiledExpression = nullptr;
2283-
m_currentVar = m_functions.cend();
2284-
m_varFound = false;
2285-
#ifndef TE_NO_BOOKKEEPING
2286-
m_usedFunctions.clear();
2287-
m_usedVars.clear();
2288-
#endif
2289-
m_resolvedVariables.clear();
2276+
reset_state();
22902277
if (get_list_separator() == get_decimal_separator())
22912278
{
22922279
throw std::runtime_error("List and decimal separators cannot be the same");

tinyexpr.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ class te_parser
262262
m_decimalSeparator = that.m_decimalSeparator;
263263
m_listSeparator = that.m_listSeparator;
264264

265+
reset_state();
266+
265267
return *this;
266268
}
267269

@@ -624,6 +626,24 @@ class te_parser
624626
static std::string info();
625627

626628
private:
629+
/// Reset everything from previous call.
630+
void reset_state()
631+
{
632+
m_errorPos = te_parser::npos;
633+
m_lastErrorMessage.clear();
634+
m_result = te_nan;
635+
m_parseSuccess = false;
636+
te_free(m_compiledExpression);
637+
m_compiledExpression = nullptr;
638+
m_currentVar = m_functions.cend();
639+
m_varFound = false;
640+
#ifndef TE_NO_BOOKKEEPING
641+
m_usedFunctions.clear();
642+
m_usedVars.clear();
643+
#endif
644+
m_resolvedVariables.clear();
645+
}
646+
627647
/// @brief Resets any resolved variables from USR if not being cached.
628648
void reset_usr_resolved_if_necessary()
629649
{

0 commit comments

Comments
 (0)