]> git.lizzy.rs Git - rust.git/commit
fix O(n^2) perf bug for std::io::fs::walk_dir
authorAaron Turon <aturon@mozilla.com>
Thu, 24 Apr 2014 00:09:58 +0000 (17:09 -0700)
committerAaron Turon <aturon@mozilla.com>
Thu, 24 Apr 2014 17:34:13 +0000 (10:34 -0700)
commitb536d2bb763d478dbf96c035dbd5b68b5ff639b9
tree2819a98060d80a93b68fc455bcb40c824f98d7ae
parent3157c3e95b3f8d217e4a1e1e7f93939866e74472
fix O(n^2) perf bug for std::io::fs::walk_dir

The `walk_dir` iterator was simulating a queue using a vector (in particular, using `shift`),
leading to O(n^2) performance. Since the order was not well-specified (see issue #13411),
the simplest fix is to use the vector as a stack (and thus yield a depth-first traversal).
This patch does exactly that.  It leaves the order as originally specified -- "some top-down
order" -- and adds a test to ensure a top-down traversal.

Note that the underlying `readdir` function does not specify any particular order, nor
does the system call it uses.

Closes #13411.
src/libstd/io/fs.rs