Re: Initing sublacss with superclass method

David Chisnall <[email protected]> Fri, 18 Jul 2025 11:24:54 +0100
Newsgroups gmane.comp.lib.gnustep.devel
Message-ID <[email protected]>
--Apple-Mail=_7D311098-A210-4255-B68C-EF71395E1BF0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8

On 18 Jul 2025, at 10:07, richard <[email protected]> wrote:
>=20
> I don't know what OSX does, and having methods of a mutable class =
(other than -copy...) return immutable instances is unusual/unintuitive, =
but from a performance point of view (because character sets can consume =
a lot of memory) it makes complete sense for these methods to return =
shared/singleton instances of immutable character sets.

If I remember correctly, GNUstep uses an idiom in a few places where =
there=E2=80=99s a =E2=80=98mutable=E2=80=99 subclass that lazily =
delegates to an immutable singleton until a mutator method is called, at =
which point it does the lazy copy and swizzles its ISA to the proper =
mutable version.

David


--Apple-Mail=_7D311098-A210-4255-B68C-EF71395E1BF0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html><head><meta http-equiv=3D"content-type" content=3D"text/html; =
charset=3Dutf-8"></head><body style=3D"overflow-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;">On 18 Jul =
2025, at 10:07, richard &lt;[email protected]&gt; =
wrote:<br><div><blockquote type=3D"cite"><br =
class=3D"Apple-interchange-newline"><div><div style=3D"caret-color: =
rgb(0, 0, 0); font-family: Helvetica; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration: none; font-size: 16px;">I don't know what OSX does, and =
having methods of a mutable class (other than -copy...) return immutable =
instances is unusual/unintuitive, but from a performance point of view =
(because character sets can consume a lot of memory) it makes complete =
sense for these methods to return shared/singleton instances of =
immutable character sets.</div></div></blockquote><br></div><div>If I =
remember correctly, GNUstep uses an idiom in a few places where =
there=E2=80=99s a =E2=80=98mutable=E2=80=99 subclass that lazily =
delegates to an immutable singleton until a mutator method is called, at =
which point it does the lazy copy and swizzles its ISA to the proper =
mutable =
version.</div><div><br></div><div>David</div><div><br></div></body></html>=

--Apple-Mail=_7D311098-A210-4255-B68C-EF71395E1BF0--