Page MenuHomePhabricator

rustfilepatterns: shorter code for concatenating slices
ClosedPublic

Authored by valentin.gatienbaron on Aug 26 2019, 12:16 AM.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Alphare accepted this revision.Aug 26 2019, 2:38 AM
kevincox accepted this revision.Aug 28 2019, 5:26 AM
kevincox added inline comments.
rust/hg-core/src/filepatterns.rs
162

I don't think you need the &_[..]. https://rust.godbolt.org/z/Wo-vza

rust/hg-core/src/filepatterns.rs
162

Indeed, although it took a compiler upgrade.
I don't really understand why the compiler accepts the change here but not in the other places. It seems a bit random to remove the borrow only here. What do you think about the next commit? It would remove the &_[..] more predictably.

kevincox added inline comments.Aug 28 2019, 7:48 AM
rust/hg-core/src/filepatterns.rs
162

For the other ones I think the problem is that it gets the element type from the first element as &Vec<u8>. I think a better approach then creating the wrapper function is doing [vec.as_slice(), b"foobar"].concat().

valentin.gatienbaron marked 2 inline comments as done.Aug 28 2019, 7:59 AM
valentin.gatienbaron added inline comments.
rust/hg-core/src/filepatterns.rs
162

I see. So the reason why the code above was accepted is because pattern was already a &[u8], and not a &Vec<u8>. Thanks!

valentin.gatienbaron marked an inline comment as done.Aug 28 2019, 8:00 AM
This revision was not accepted when it landed; it landed in state Needs Review.
This revision was automatically updated to reflect the committed changes.