Skip to content

Commit

Permalink
Handle listReverse of 1 element as a special case
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Apr 4, 2016
1 parent 18c51d6 commit b4f223e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions SimulationRuntime/c/meta/meta_modelica_builtin.c
Expand Up @@ -394,13 +394,15 @@ modelica_metatype boxptr_stringUpdateStringChar(threadData_t *threadData,metamod
modelica_metatype listReverse(modelica_metatype lst)
{
modelica_metatype res = NULL;

if (MMC_NILTEST(lst) || MMC_NILTEST(MMC_CDR(lst))) {
// 0/1 elements are already reversed
return lst;
}
res = mmc_mk_nil();
while (!MMC_NILTEST(lst))
{
do {
res = mmc_mk_cons(MMC_CAR(lst),res);
lst = MMC_CDR(lst);
}
} while (!MMC_NILTEST(lst));
return res;
}

Expand Down

0 comments on commit b4f223e

Please sign in to comment.