Skip to content

Fix: tighten loop bound in first_switch_pairs#2759

Merged
keon merged 1 commit into
keon:mainfrom
vdl299:fix_switch_pairs_loop_bound
May 25, 2026
Merged

Fix: tighten loop bound in first_switch_pairs#2759
keon merged 1 commit into
keon:mainfrom
vdl299:fix_switch_pairs_loop_bound

Conversation

@vdl299

@vdl299 vdl299 commented May 24, 2026

Copy link
Copy Markdown

Summary

  • Tighten loop bound in first_switch_pairs
  • Remove redundant empty-check guard made unnecessary by the fix

Improvement

range(len(storage_stack)) was a misleading loop bound — the loop actually
ran at most len/2 iterations, relying on internal break guards to terminate
correctly. Replaced with (len(storage_stack)+1)//2 which reflects the exact
number of iterations needed. The first empty-check guard became redundant and
was removed.

Test plan

  • python -m pytest tests/test_stack.py - 10 tests pass

@keon keon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the contribution!

@keon keon merged commit f989616 into keon:main May 25, 2026
4 checks passed
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.

2 participants