[squeak-dev] Undeclared -> WeakIdentityDictionary -> wrong tally -> wrong #size
marcel.taeumel
Marcel.Taeumel at hpi.de
Wed Feb 26 13:25:52 UTC 2020
Okay. I will add some #testIsEmpty for our weak collections to show the
issue. Then I will override all #isEmpty back to the original approach using
#do:. I will not remove the optimization in HashedCollection >> #isEmpty.
The tests will look like this:
testIsEmpty
| ws o1 o2 |
o1 := Object new.
o2 := Object new.
ws := WeakSet new.
self assert: ws isEmpty.
ws add: o1.
ws add: o2.
self deny: ws isEmpty.
Smalltalk garbageCollect.
self deny: ws isEmpty.
o1 := nil.
o2 := nil.
Smalltalk garbageCollect.
self assert: ws isEmpty.
Why am I doing this? See ReleaseTest >> #testUndeclared :-)
Best,
Marcel
marcel.taeumel wrote
> Hmm... for all kinds of HashedCollection, there is #size and #slowSize.
> The
> latter is more precise for weak collections, which answer only an upper
> bound via #size. Because they cannot know better. While this might be
> resolved with using ephemerons at some point, I still wonder whether
> #isEmpty should really just use the tally or not:
>
> HashedCollection >> #isEmpty
> ^tally = 0
>
> We added this in 10/20/2016. Maybe we should override #isEmpty in all our
> weak collections if they do not rely on #do as intended in Collection:
>
> Collection >> #isEmpty
> self do: [:element | ^ false].
> ^ true
>
> #do: works fine for those weak collections. I suppose it is as slow as
> #slowSize. :-)
>
> Best,
> Marcel
>
>
> marcel.taeumel wrote
>> Hi, there.
>>
>> In Squeak 5.3 RC1, the size of Undeclared is wrong. It should be 1 (which
>> is also wrong but I fixed that), but is actually 31.
>>
>> WeakIdentityDictionary (HashedCollection) >> #size
>> ^ tally
>>
>> Well, there might be a bug lurking somewhere. Maybe an update script
>> messed up the state of Undeclared in particular. I don't know.
>>
>> What should I do? Just fix that value for tally in Undeclared?
>>
>> Best,
>> Marcel
>>
>> P.S.: The #capacity of Undeclared is 3, which is correct because the
>> internal WeakArray array has that size.
>
>
>
>
>
> --
> Sent from: http://forum.world.st/Squeak-Dev-f45488.html
--
Sent from: http://forum.world.st/Squeak-Dev-f45488.html
More information about the Squeak-dev
mailing list
|