Skip to content
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

Replace recursive call with while loop to prevent stack overflow. #5884

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

VasilErema
Copy link

@VasilErema VasilErema commented Oct 1, 2024

First time contributor checklist

Contributor checklist

  • My commits are rebased on the latest main branch
  • My commits are in nice logical chunks
  • My contribution is fully baked and is ready to be merged as is
  • I have tested my contribution on these devices:
  • Simulator iPhone 16 PRO , iOS 18.0

Description

  • Recursive call might cause stack overflow if called to many times.
  • Improvement: replace recursive call with while loop, that won't be affected by the issue.

P.S. I had no stack overflow with old/new code when tested - there was no recursive calls. I picked it as a small first contribution.

self.isRunning = true
defer { self.isRunning = false }
// Run while there is a next timestamp.
while true {

Choose a reason for hiding this comment

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

This loop never breaks?

Copy link
Author

Choose a reason for hiding this comment

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

It can break. If there is no more timestamps to handle it returns on line 92.
Functionally it is the same as before.

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

Successfully merging this pull request may close these issues.

2 participants