fixed a rdonly flag bug in moo_shallowcpy()
added SequenceableCollection>>swap:with:
This commit is contained in:
parent
e036f3f6d7
commit
6b2cb6f9df
@ -112,6 +112,8 @@ extend Apex
|
|||||||
## -------------------------------------------------------
|
## -------------------------------------------------------
|
||||||
method(#dual,#primitive,#lenient) _shallowCopy.
|
method(#dual,#primitive,#lenient) _shallowCopy.
|
||||||
method(#dual,#primitive) shallowCopy.
|
method(#dual,#primitive) shallowCopy.
|
||||||
|
method(#dual,#primitive,#lenient) _copy. ## alias to _shallowCopy
|
||||||
|
method(#dual,#primitive) copy. ## alias to shallowCopy
|
||||||
|
|
||||||
## -------------------------------------------------------
|
## -------------------------------------------------------
|
||||||
## -------------------------------------------------------
|
## -------------------------------------------------------
|
||||||
|
@ -110,6 +110,17 @@ class SequenceableCollection(Collection)
|
|||||||
|
|
||||||
startIndex to: stopIndex do: [:i | aBlock value: (self at: i) value: i].
|
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.
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## -------------------------------------------------------------------------------
|
## -------------------------------------------------------------------------------
|
||||||
|
@ -3800,6 +3800,7 @@ static pf_t pftab[] =
|
|||||||
{ "Apex_basicShiftFrom:to:count:", { moo_pf_basic_shift, 3, 3 } },
|
{ "Apex_basicShiftFrom:to:count:", { moo_pf_basic_shift, 3, 3 } },
|
||||||
{ "Apex_basicSize", { moo_pf_basic_size, 0, 0 } },
|
{ "Apex_basicSize", { moo_pf_basic_size, 0, 0 } },
|
||||||
{ "Apex_class", { moo_pf_class, 0, 0 } },
|
{ "Apex_class", { moo_pf_class, 0, 0 } },
|
||||||
|
{ "Apex_copy", { moo_pf_shallow_copy, 0, 0 } },
|
||||||
{ "Apex_hash", { pf_hash, 0, 0 } },
|
{ "Apex_hash", { pf_hash, 0, 0 } },
|
||||||
{ "Apex_isKindOf:", { moo_pf_is_kind_of, 1, 1, } },
|
{ "Apex_isKindOf:", { moo_pf_is_kind_of, 1, 1, } },
|
||||||
{ "Apex_perform", { pf_perform, 1, MA } },
|
{ "Apex_perform", { pf_perform, 1, MA } },
|
||||||
|
@ -1082,6 +1082,7 @@ moo_oop_t moo_shallowcopy (moo_t* moo, moo_oop_t oop)
|
|||||||
|
|
||||||
/* copy the payload */
|
/* copy the payload */
|
||||||
MOO_MEMCPY (z + 1, oop + 1, get_payload_bytes(moo, oop));
|
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;
|
return z;
|
||||||
#else
|
#else
|
||||||
@ -1095,6 +1096,7 @@ moo_oop_t moo_shallowcopy (moo_t* moo, moo_oop_t oop)
|
|||||||
moo_popvolat(moo);
|
moo_popvolat(moo);
|
||||||
|
|
||||||
MOO_MEMCPY (z, oop, total_bytes);
|
MOO_MEMCPY (z, oop, total_bytes);
|
||||||
|
MOO_OBJ_SET_FLAGS_RDONLY (z, 0); /* a copied object is not read-only */
|
||||||
return z;
|
return z;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -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;
|
return MOO_PF_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------
|
||||||
* BASIC ACCESS
|
* BASIC ACCESS
|
||||||
* -------------------------------------------------------------------------------- */
|
* -------------------------------------------------------------------------------- */
|
||||||
|
Loading…
Reference in New Issue
Block a user