In MQ2Melee it can decide to equipment manage to carry out an action, then swap again afterwards.
The original code, notes the current item ID, does some activity, and then calls Equip, to ensure the initial item ID is back afterwards. However it does this by looking in the bags first, before looking elsewhere. Equip, assumes that a change has taken place and must be made.
If you have two items of the same ID, one already equipped and the other in the bags, then the code shuffles these around. This will be seen as the item blinks on the cursor, as shuffled between gear slot and inventory slot. It can also be seen by the duplicate moving in the inventory from a higher slot, to the first freely available slot.
This is made worse, if the item in inventory is not attuned, is tradeable, as it will try to equip and present the box asking to attune it. Leading to the potential of several "attune?" boxes on screen, which I have seen.
The short defensive code change to Equip, simple checks the requested equip ID, against the item ID in the target slot. If they are the same, it takes no action, and returns a positve result.
A further gain, also considered with regards a unique item. As the code assumes it needs to change it looks in the bags, and wouldn't find it. Then would look to equipment and see it's there and return happy. This fix, by first checking the target slot against the request will negate that processing of searching the bags.