Nikolay Sivov (@nsivov) commented about dlls/scrrun/dictionary.c:
TRACE("%p, %s, %s.\n", iface, debugstr_variant(key), debugstr_variant(newkey));
- if ((pair = get_keyitem_pair(dictionary, key))) - { - /* found existing pair for a key, add new pair with new key - and old item and remove old pair after that */ + if (!(pair = get_keyitem_pair(dictionary, key))) + return CTL_E_ELEMENT_NOT_FOUND;
- hr = IDictionary_Add(iface, newkey, &pair->item); - if (FAILED(hr)) - return hr; + /* The key is renamed in place, preserving its value and enumeration + position; only collisions with a different pair are rejected. */ + if (get_keyitem_pair(dictionary, newkey) && get_keyitem_pair(dictionary, newkey) != pair) + return CTL_E_KEY_ALREADY_EXISTS;
We don't need to call same lookup twice. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10961#note_140977