Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Handler for Copying Immutable Plists and Strings #1520

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/plist.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,18 +971,19 @@ Obj FuncIS_PLIST_REP (
**
** 'CleanPlist' is the function in 'CleanObjFuncs' for plain lists.
*/
Obj CopyPlist (
Obj list,
Int mut )
Obj CopyPlistImm(Obj list, Int mut)
{
GAP_ASSERT(!IS_MUTABLE_OBJ(list));
return list;
}

Obj CopyPlist(Obj list, Int mut)
{
Obj copy; /* copy, result */
Obj tmp; /* temporary variable */
UInt i; /* loop variable */

/* don't change immutable objects */
if ( ! IS_MUTABLE_OBJ(list) ) {
return list;
}
GAP_ASSERT(IS_MUTABLE_OBJ(list));

/* make a copy */
if ( mut ) {
Expand Down Expand Up @@ -4619,7 +4620,7 @@ static Int InitKernel (
/* install the copy list methods */
for ( t1 = T_PLIST; t1 <= LAST_PLIST_TNUM; t1 += 2 ) {
CopyObjFuncs [ t1 ] = CopyPlist;
CopyObjFuncs [ t1 +IMMUTABLE ] = CopyPlist;
CopyObjFuncs [ t1 +IMMUTABLE ] = CopyPlistImm;
CopyObjFuncs [ t1 +COPYING ] = CopyPlistCopy;
CopyObjFuncs [ t1 +IMMUTABLE +COPYING ] = CopyPlistCopy;
CleanObjFuncs[ t1 ] = CleanPlist;
Expand Down
15 changes: 9 additions & 6 deletions src/stringobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,16 +586,19 @@ Obj TypeString (
**
** 'CleanString' is the function in 'CleanObjFuncs' for strings.
*/
Obj CopyStringImm(Obj list, Int mut)
{
GAP_ASSERT(!IS_MUTABLE_OBJ(list));
return list;
}

Obj CopyString (
Obj list,
Int mut )
{
Obj copy; /* handle of the copy, result */

/* just return immutable objects */
if ( ! IS_MUTABLE_OBJ(list) ) {
return list;
}
GAP_ASSERT(IS_MUTABLE_OBJ(list));

/* make object for copy */
if ( mut ) {
Expand Down Expand Up @@ -2563,9 +2566,9 @@ static Int InitKernel (
}

/* install the copy method */
for ( t1 = T_STRING; t1 <= T_STRING_SSORT; t1++ ) {
for ( t1 = T_STRING; t1 <= T_STRING_SSORT; t1+=2 ) {
CopyObjFuncs [ t1 ] = CopyString;
CopyObjFuncs [ t1 +IMMUTABLE ] = CopyString;
CopyObjFuncs [ t1 +IMMUTABLE ] = CopyStringImm;
CleanObjFuncs[ t1 ] = CleanString;
CleanObjFuncs[ t1 +IMMUTABLE ] = CleanString;
CopyObjFuncs [ t1 +COPYING ] = CopyStringCopy;
Expand Down