fixed a rdonly flag bug in moo_shallowcpy()

added SequenceableCollection>>swap:with:
This commit is contained in:
hyunghwan.chung 2019-06-19 09:21:28 +00:00
parent e036f3f6d7
commit 6b2cb6f9df
5 changed files with 16 additions and 1 deletions

View File

@ -112,6 +112,8 @@ extend Apex
## -------------------------------------------------------
method(#dual,#primitive,#lenient) _shallowCopy.
method(#dual,#primitive) shallowCopy.
method(#dual,#primitive,#lenient) _copy. ## alias to _shallowCopy
method(#dual,#primitive) copy. ## alias to shallowCopy
## -------------------------------------------------------
## -------------------------------------------------------

View File

@ -110,6 +110,17 @@ class SequenceableCollection(Collection)
startIndex to: stopIndex do: [:i | aBlock value: (self at: i) value: i].
}
method swap: anIndex with: anotherIndex
{
## the subclass must implement at: and at:put for this to work.
| tmp |
tmp := self at: anIndex.
self at: anIndex put: (self at: anotherIndex).
self at: anotherIndex put: tmp.
}
}
## -------------------------------------------------------------------------------

View File

@ -3800,6 +3800,7 @@ static pf_t pftab[] =
{ "Apex_basicShiftFrom:to:count:", { moo_pf_basic_shift, 3, 3 } },
{ "Apex_basicSize", { moo_pf_basic_size, 0, 0 } },
{ "Apex_class", { moo_pf_class, 0, 0 } },
{ "Apex_copy", { moo_pf_shallow_copy, 0, 0 } },
{ "Apex_hash", { pf_hash, 0, 0 } },
{ "Apex_isKindOf:", { moo_pf_is_kind_of, 1, 1, } },
{ "Apex_perform", { pf_perform, 1, MA } },

View File

@ -1082,6 +1082,7 @@ moo_oop_t moo_shallowcopy (moo_t* moo, moo_oop_t oop)
/* copy the payload */
MOO_MEMCPY (z + 1, oop + 1, get_payload_bytes(moo, oop));
MOO_OBJ_SET_FLAGS_RDONLY (z, 0); /* a copied object is not read-only */
return z;
#else
@ -1095,6 +1096,7 @@ moo_oop_t moo_shallowcopy (moo_t* moo, moo_oop_t oop)
moo_popvolat(moo);
MOO_MEMCPY (z, oop, total_bytes);
MOO_OBJ_SET_FLAGS_RDONLY (z, 0); /* a copied object is not read-only */
return z;
#endif
}

View File

@ -253,7 +253,6 @@ moo_pfrc_t moo_pf_shallow_copy (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
return MOO_PF_SUCCESS;
}
/* --------------------------------------------------------------------------------
* BASIC ACCESS
* -------------------------------------------------------------------------------- */