Skip to content

Commit

Permalink
vec_no_clone with list of elements now falling back to vec macro, inc…
Browse files Browse the repository at this point in the history
…reasing performance dramatically
  • Loading branch information
jofas committed Aug 18, 2022
1 parent 20a6c2c commit 4b772d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@ assert_eq!(*unshared_vec[0].borrow(), 1);
assert_eq!(*unshared_vec[1].borrow(), 0);
```

You can also use the macro with a list of elements, like `vec!`,
though `vec!` is probably faster:
You can also use the macro with a list of elements, like `vec!`:

```rust
use map_macro::vec_no_clone;
Expand Down
6 changes: 6 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@
* [x] documentation

* [x] publish `v0.2.2`

* [x] `vec_no_clone` fallback to `vec`

* [ ] `btree_map`

* [ ] `btree_set`
15 changes: 1 addition & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ macro_rules! set {
///
#[macro_export]
macro_rules! vec_no_clone {
(@to_unit $($_:tt)*) => (());
(@count $($tail:expr),*) => (
<[()]>::len(&[$(vec_no_clone!(@to_unit $tail)),*])
);

{$v: expr; $c: expr} => {
{
let mut vec = Vec::with_capacity($c);
Expand All @@ -119,15 +114,7 @@ macro_rules! vec_no_clone {
};
{$($v: expr),* $(,)?} => {
{
let mut vec = Vec::with_capacity(
vec_no_clone!(@count $($v),*),
);

$(
vec.push($v);
)*

vec
vec![$($v),*]
}
};
}

0 comments on commit 4b772d6

Please sign in to comment.