When this methods was added, there was a debate whether it should be optimized (inlined as you did) or not. The argument behind the original implementation was that subclasses only had to override #at:ifAbsent: to change the behavior of public lookup methods #at:, #at:ifAbsent:, #at:ifPresent:, #at:ifPresent:ifAbsent: and #at:ifAbsentPut:.
Since then #at:ifPresent:ifAbsentPut: was added, which didn't follow that idea. I'm strongly against external packages subclassing collections (exactly for this reason: it limits what core developer can do), so I have no problem with these changes, but they may break some packages out there.
Levente
P.S.: Sometimes swapping the branches: #at:ifAbsent:ifPresent: would improve code legibility, so perhaps that should be added as well. P.P.S.: I think overall performance could be better if this were the main method other variants were using if we want to follow that idea.
On Sat, 10 Mar 2018, commits@source.squeak.org wrote:
Eliot Miranda uploaded a new version of Collections to project The Trunk: http://source.squeak.org/trunk/Collections-eem.784.mcz
==================== Summary ====================
Name: Collections-eem.784 Author: eem Time: 9 March 2018, 5:18:51.529302 pm UUID: 1862bd2e-3307-4973-b7b1-c8f6ad8d5f53 Ancestors: Collections-ul.783
Provide more efficient implementation(s) of at:ifPresent:ifAbsent: given impending use in the Compiler.
=============== Diff against Collections-ul.783 ===============
Item was changed: ----- Method: Dictionary>>at:ifPresent:ifAbsent: (in category 'accessing') ----- at: key ifPresent: oneArgBlock ifAbsent: absentBlock
- "Lookup the given key in the receiver. If it is present, answer the
value of evaluating the oneArgBlock with the value associated
with the key, otherwise answer the value of absentBlock."
- ^(array at: (self scanFor: key))
ifNil: [absentBlock value]
ifNotNil: [:association| oneArgBlock value: association value]!
- "Lookup the given key in the receiver. If it is present, answer the value of evaluating the oneArgBlock with the value associated with the key, otherwise answer the value of absentBlock."
- self at: key ifPresent:[:v| ^oneArgBlock value: v].
- ^absentBlock value!
Item was added:
- ----- Method: WeakIdentityDictionary>>at:ifPresent:ifAbsent: (in category 'accessing') -----
- at: key ifPresent: oneArgBlock ifAbsent: absentBlock
- "Lookup the given key in the receiver. If it is present, answer the
value of evaluating the oneArgBlock with the value associated
with the key, otherwise answer the value of absentBlock."
- ^(array at: (self scanFor: key))
ifNil: [absentBlock value]
ifNotNil:
[:association|
association == vacuum
ifTrue: [absentBlock value]
ifFalse: [oneArgBlock value: association value]]!