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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify RawDir iteration #515

Merged
merged 1 commit into from Jan 17, 2023
Merged

Simplify RawDir iteration #515

merged 1 commit into from Jan 17, 2023

Conversation

SUPERCILEX
Copy link
Contributor

@SUPERCILEX SUPERCILEX commented Jan 15, 2023

Recently had to look at this again and unsurprisingly I have no idea what past me was thinking. 馃槄

Basic idea: get rid of the loop. It ain't needed.

New control flow:

  • If we've read up to the initialized bytes (including 0 >= 0), we need to refill the buffer.
  • initialized and offset only ever need to be reset when we actually succeeded in filling the buffer. On an error, we return which means that if next gets called again, the offset >= initialized check will run again with the same result since nothing changed.

Note: the diff is overcomplicating things, the main change is just swapping where the syscall and buffer consumption occur.

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
@sunfishcode
Copy link
Member

Makes sense!

@sunfishcode sunfishcode merged commit bc47644 into bytecodealliance:main Jan 17, 2023
sunfishcode pushed a commit that referenced this pull request Jan 17, 2023
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
sunfishcode pushed a commit that referenced this pull request Jan 17, 2023
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
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.

None yet

2 participants