Skip to content

Better set_if_unequal() #17

@kpreid

Description

@kpreid

Cell::set_if_unequal() has the caveat that "this executes PartialEq::eq() with the lock held". We can do better than that:

  1. Acquire the lock.
  2. Swap the new value in.
  3. Release the lock.
  4. Compare the old value.
  5. If unequal, send a notification.

This is a visible behavior change because it swaps values even if unnecessary, so if downstream cares at all about differences ignored by PartialEq like pointer addresses, it could detect the difference, but that should be acceptable in nearly all cases. Still, I think the new operation should be a new method with clear documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions