Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
im-util:
SortBy
optimises Remove
+ Insert
to Set
in another case
In the `SortBy` stream adapter, when the user is applying a `observable_vector.set(…)` that should result in a `Remove` + `Insert`, it sometimes can be optimised into a single `Set`. This happens when the `old_index` and the `new_index` (resp. the sorted index of the value to be updated, and the sorted index of the new value) are equal. But actually, when `old_index` is lower than `new_index`, there is _another_ missed optimisation in one particular context. If `old_index == new_index - 1`, then we are actually updating the same location. Indeed, the code is already making it clear: when `old_index < new_index`, we need to subtract 1 to `new_index` because removing the value at `old_index` is shifting all values at its right, thus 1 must be subtracted to `new_index`. The missed opportunity for an optimisation here is when `old_index == new_index - 1`, where it's clear that the same position is updated. This patch handles this situation. The tests are updated accordingly.
- Loading branch information