# fs: Optimize Dir.deleteTree for non-deeply-nested directories · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/274d19575ea1ebaea593cdca7c5afa8303153cb4)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 274d19575ea1ebaea593cdca7c5afa8303153cb4

Requested commit: 274d19575ea1ebaea593cdca7c5afa8303153cb4

Commit: 274d19575ea1ebaea593cdca7c5afa8303153cb4

Tree: cdfc0fdc70ae18f08a6e1e5faf2c4455c32f5391

Author: Ryan Liptak

Committer: Ryan Liptak

## Message

```
fs: Optimize Dir.deleteTree for non-deeply-nested directories

`deleteTree` now uses a stack-allocated stack for the first 16 nested directories, and then falls back to the previous implementation (which only keeps 1 directory open at a time) when it runs out of room in its stack. This allows the function to perform as well as a recursive implementation for most use-cases without needing allocation or introducing the possibility of stack overflow.

```

## Parents

- [e9889cd25ff219f2f5ac7a336c4f99a577b19d44](https://git.cafe/gitcafe/zig/commit/e9889cd25ff219f2f5ac7a336c4f99a577b19d44?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/274d19575ea1ebaea593cdca7c5afa8303153cb4?format=markdown)
