-
Notifications
You must be signed in to change notification settings - Fork 97
fix: use deterministic comparison ordering #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -859,18 +859,17 @@ def _item_replaced(self, path, key, item): | |||||||||||||||
| }, pointer_cls=self.pointer_cls)) | ||||||||||||||||
|
|
||||||||||||||||
| def _compare_dicts(self, path, src, dst): | ||||||||||||||||
| src_keys = set(src.keys()) | ||||||||||||||||
| dst_keys = set(dst.keys()) | ||||||||||||||||
| added_keys = dst_keys - src_keys | ||||||||||||||||
| removed_keys = src_keys - dst_keys | ||||||||||||||||
| added_keys = [key for key in dst.keys() if key not in src.keys()] | ||||||||||||||||
| removed_keys = [key for key in src.keys() if key not in dst.keys()] | ||||||||||||||||
| intersection = [key for key in src.keys() if key in dst.keys()] | ||||||||||||||||
|
Comment on lines
+863
to
+864
|
||||||||||||||||
| removed_keys = [key for key in src.keys() if key not in dst.keys()] | |
| intersection = [key for key in src.keys() if key in dst.keys()] | |
| dst_keys = set(dst.keys()) | |
| removed_keys = [key for key in src.keys() if key not in dst_keys] | |
| intersection = [key for key in src.keys() if key in dst_keys] |
Copilot
AI
Aug 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also has O(n²) complexity. Use intersection = [key for key in src if key in dst] for better performance.
| intersection = [key for key in src.keys() if key in dst.keys()] | |
| intersection = list(set(src.keys()) & set(dst.keys())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The list comprehension with
if key not in src.keys()will result in O(n²) time complexity for large dictionaries sinceinoperation on dict.keys() is O(n). Consider usingadded_keys = [key for key in dst if key not in src]instead, which maintains O(n) complexity.