diff --git a/src/term.c b/src/term.c index 00890e1..77fe57f 100644 --- a/src/term.c +++ b/src/term.c @@ -420,6 +420,28 @@ termDuplicate (const Term term) return newterm; } +//! Make a deep copy of a term node (one-level) +/** + * Leaves are not copied. + *@return If the original was a leaf, then the pointer is simply returned. Otherwise, new memory is allocated and the node is copied recursively. + *\sa termDuplicateDeep() + */ + +Term +termNodeDuplicate (const Term term) +{ + Term newterm; + + if (term == NULL) + return NULL; + if (realTermLeaf (term)) + return term; + + newterm = (Term) memAlloc (sizeof (struct term)); + memcpy (newterm, term, sizeof (struct term)); + return newterm; +} + //! Make a true deep copy of a term. /** * Currently, it this function is not to be used, so we can be sure leaf nodes occur only once in the system. diff --git a/src/term.h b/src/term.h index 72da251..33e8866 100644 --- a/src/term.h +++ b/src/term.h @@ -158,6 +158,7 @@ int termInTerm (Term t, Term tsub); void termPrint (Term term); void termTuplePrint (Term term); Term termDuplicate (const Term term); +Term termNodeDuplicate (const Term term); Term termDuplicateDeep (const Term term); Term termDuplicateUV (Term term); void termDelete (const Term term); diff --git a/src/termlist.c b/src/termlist.c index 57bd39e..943d5e2 100644 --- a/src/termlist.c +++ b/src/termlist.c @@ -642,7 +642,7 @@ termLocal (Term t, Termlist fromlist, Termlist tolist, const int runid) } else { - Term newt = termDuplicate (t); + Term newt = termNodeDuplicate (t); if (realTermTuple (t)) { newt->left.op1 = termLocal (t->left.op1, fromlist, tolist, runid);