New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
21475 Use ifNil: in HashedCollection grow #1010
21475 Use ifNil: in HashedCollection grow #1010
Conversation
Test failures unrelated |
for #isNil, if it is done in a very very tight loop, it might be a bit slower than == nil. But the good thing is that we do have #ifNil:IfNotNil: which compiles to the same byte code at == nil ifTrue: Another thing we did run into in the past is message send vs. none: #isNil does an interrupt check, == nil not. In class Process this can lead to problems (in other real world use cases normaly not). |
I think "== nil" here is to ensure that we do not send any message to contained objects. It is important when we work with some "naked objects" which has no messages at all. Maybe core collections are already not safe for such cases. But if they are, it will break them. |
And from this point of view "== nil" is better then ifNotNil because it is explicitly have no message send. While ifNotNil optimisation can be disabled in system |
That optimisation can be disabled in system is a technical detail. For readability I would also vote for #ifNotNil: as also Herby Vojčík wrote. |
It is not technical detail. |
@dionisiydk For me #== and #ifNotNil: are both in the Kernel, both are understand from ProtoObject(s) downwards ... so whatever naked object the collection contains it should be able to work with/understand both. No? |
You can always create class from nil without ProtoObject subclassing. Really safe container should assume nothing about underlying objects. But now I realized that HashedCollections are not safe containers anyway. They send hash related messages to objects. So it is fine to use ifNotNil: here. Sorry for the noise. |
https://pharo.fogbugz.com/f/cases/21475/Use-isNil-in-HashedCollection-grow