- Notifications
You must be signed in to change notification settings - Fork 13.9k
Implement create_dir_all() to operate iteratively instead of recursively #148196
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?
Implement create_dir_all() to operate iteratively instead of recursively #148196
Conversation
… of recursively.
|
…ruct for collecting uncreated directories
| Why does this need to manipulate a list of |
| 🥴 Answer to jubilee: It's not a reversible iterator!!! |
| jubilee's counterargument to jubilee's counterargument: Okay, so we'd have to use |
| Please feel free to question/reject my comment/suggestion if you feel it is incorrect/scope-creeping, I only am bringing it up because I had precisely this thought after wondering why code I had earlier written elsewhere was doing |
| Followup response to jubilee: what about in the tune of "Khaaan!": RELATIVE PAAATHS! |
…t directory and uses a boxed slice to pre-allocate memory for uncreated directories and iterate through & create them efficiently
| Hey jubilee, I took your suggestion and iterate through the Ancestors Iterator. One thing that I did differently however is that instead of using Does this approach look good to you? |
| Yes, allocating once instead of many times sounds like a reasonable improvement in the spirit of my note, so if others are cool with it, then I'm cool! That way it's "just" a classic space vs. time tradeoff and getting the main improvement we're looking for. |
| Hi @tgross35, I noticed that you were the assignee for this pull request. I wanted to ask if there is anything I should change with this PR/commits or if everything looks alright? |
| I haven't looked at this yet so I'm going to who has. (I know it's at your limit so feel free to reroll again or throw it back if you want) |
|
|
The current implementation of
create_dir_all(...)in std::fs operates recursively. As mentioned in #124309, this could run into a stack overflow with big paths. To avoid this stack overflow issue, this PR implements the method in an iterative manner, preserving the documented behavior of: