Re: RFC WeakRefs
| From: | Rowan Collins | Date: | Fri, 18 May 2018 11:58:51 +0000 |
| Subject: | Re: RFC WeakRefs | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-102118@lists.php.net to get a copy of this message | ||
On 17 May 2018 10:35:11 BST, Etienne Kneuss <colder@php.net> wrote:
>That said, if the plan is to subsume pecl-weakref, I suggest we also
>reimplement weakmaps, which offer a convenient way of storing
>meta/cache
>data and is not implementable in userland without trade-offs.
It looks to me like WeakMap would be fairly trivial to implement in userland as a combination of
WeakRef, ArrayAccess, Iterable, and an internal SplObjectStorage for the ability to use objects as
keys (although I'm not clear why it uses object keys in the first place).
The only part that seems hard to write efficiently is Countable support, since you'd have to
iterate the internal hash checking for unset objects. I suppose iteration would also slow down a bit
of lots of the references were now unset. Is that the trade-off you're referring to, that the C
implementation has some magic to avoid?
Regards,
--
Rowan Collins
[IMSoP]