Affects Version/s: 1.9.518, 1.9.521, 1.9.542, 1.9.562, 1.9.655, 1.9.660
Fix Version/s: None
Patch:Code and Test
The IFind protocol introduced by
CLJS-1497 (early April) had an ambiguity about whether -find implementors were responsible for the key containment checks or should assume the key was already present (i.e., never return nil). CLJS-1497 changed find? such that containment checks were always done first and -find was only looked for after. However CLJS-2013 (MapEntry and tree node fixups) was unclear about the contract and implemented -find with a key check and nil case. It also added this comment to its tests:
- Clarifies the contract of IFind to require that the implementor also perform the key check. The IFind protocol docstring is updated to reflect this. The advantage of requiring -find to do the key check (vs find) is that for some data structures find can avoid looking up an entry twice.
- Changes find to test for and use IFind first rather than testing for containment first.
- Changes all IFind implementations in core to perform key checks. Each implementation is careful to do lookups only once (rather than one lookup to test for key presence and another one to retrieve the value).
- Adds some more tests for find on a vector using degenerate keys.
- Changes the above-quoted map entry test to use -find directly, and removes the comment about ambiguity.