Reuse stored hashes in dict.fromkeys() - #8503
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [ ] test: cpython/Lib/test/test_set.py (TODO: 3) dependencies: dependent tests: (no tests depend on set) Legend:
|
Closes RustPython#8490. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
fe77067 to
324ecaa
Compare
Summary
dict.fromkeys() recomputed hash for every key even when the source already stored a hash per entry. CPython's _PyDict_FromKeys branches on PyDict_CheckExact / PyAnySet_CheckExact and feeds the hash read from the source table straight into insertdict; RustPython always iterated generically through setitem.
The checks are the exact ones CPython uses: a set or dict subclass may override iter, so reading its table directly would change what the call observes. exact_set_keys_with_hashes() is therefore separate from extract_set(), which stays subclass-inclusive for the set operations.