Skip to content

Conversation

@denini08
Copy link

Hi! First of all, thanks for the great work on this project.

I noticed that the construction of orderedScripts and orderedBlocks currently relies on checking membership in lists:

value not in orderedScripts  
value not in orderedBlocks  

This results in an O(N) lookup for each iteration, making the overall process more expensive as the lists grow. The logic is correct and clear, but the membership check itself can be optimized.

To keep the same behavior while improving performance, this PR introduces auxiliary sets:

seen_scripts = set()  
seen_blocks = set()  

These sets are used only to track which values were already added, while the lists are still responsible for preserving order.

With this change:

  • The membership test goes from O(N) to O(1) on average
  • The ordered lists keep exactly the same output
  • The intent becomes clearer: sets for fast lookup, lists for ordering

It’s a small and safe change, but it improves efficiency and makes the logic a bit more explicit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant