I debated moving it to utils, but it is not used anywhere else for now, and
its skip behavior is pretty specific to status.
Details
- Reviewers
marmoute kevincox - Group Reviewers
hg-reviewers - Commits
- rHG0d97bcb3cee9: rust-status: add util for listing a directory
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
Event Timeline
I am not a rust expert, but I don't see anything obviously wrong in there. I make a couple of minor comments.
rust/hg-core/src/dirstate/status.rs | ||
---|---|---|
68 | note: took me some time to realize that skipping the full directory if there is a .hg make sense. Because we detected a another repository and that the wc is part of that repository. Maybe follow up with a documentation update that clarify this. | |
74 | Silly question: would it make sense to sort the filename before the loop ? It might result is less bytes to move around since the entry will not be attached yet. |
rust/hg-core/src/dirstate/status.rs | ||
---|---|---|
74 | I'm not entirely sure I understand your question. |
rust/hg-core/src/dirstate/status.rs | ||
---|---|---|
74 | If I understand you code correctly you currently do: filenames = listdir() result = [(f, entry(f)) for f in filenames] result.sort() Would it make sense to do: filenames = listdir() filenames.sort() result = [(f, entry(f)) for f in filenames] |
rust/hg-core/src/dirstate/status.rs | ||
---|---|---|
74 | std::fs::read_dir returns an iterator, so I would have to collect it first, unsure if that would be more expensive... and also, a Vec of heap-allocated elements being just an array of pointers I'm not convinced that would help. Maybe we can do some benchmarking further down the line. |
rust/hg-core/src/dirstate/status.rs | ||
---|---|---|
76 | It would be more clear to do .sort_by_key(|e| e.0) And I don't think stability matters here so you could use sort_unstable_by_key. |
rust/hg-core/src/dirstate/status.rs | ||
---|---|---|
76 | I didn't realize that sort_unstable_by_key needed to return a T and not a &T, that forces a clone(). I'm not sure that matters, we'll go with the shortest code and see if that shows up in profiling later. |
rust/hg-core/src/dirstate/status.rs | ||
---|---|---|
76 | sort_unstable_by_key doesn't require the function to return a T at all. It just needs to return an Ord type. Note that &Ord is Ord automatically. https://doc.rust-lang.org/std/primitive.slice.html#method.sort_unstable_by_key |
note: took me some time to realize that skipping the full directory if there is a .hg make sense. Because we detected a another repository and that the wc is part of that repository.
Maybe follow up with a documentation update that clarify this.