Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BufMut::put_bytes(self, val, cnt) #487

Merged
merged 1 commit into from
Aug 8, 2021
Merged

Conversation

stepancheg
Copy link
Contributor

Equivalent to

for _ in 0..cnt {
    self.put_u8(val);
}

but may work faster.

Name and signature is chosen to be consistent with ptr::write_bytes.

Include three specializations:

  • Vec<u8>
  • &mut [u8]
  • BytesMut

BytesMut and &mut [u8] specializations use ptr::write, Vec<u8>
specialization uses Vec::resize.

Copy link
Member

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This seems reasonable.

src/buf/buf_mut.rs Show resolved Hide resolved
Equivalent to

```
for _ in 0..cnt {
    self.put_u8(val);
}
```

but may work faster.

Name and signature is chosen to be consistent with `ptr::write_bytes`.

Include three specializations:
* `Vec<u8>`
* `&mut [u8]`
* `BytesMut`

`BytesMut` and `&mut [u8]` specializations use `ptr::write`, `Vec<u8>`
specialization uses `Vec::resize`.
@stepancheg
Copy link
Contributor Author

Updated the doc.

Copy link
Member

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@taiki-e taiki-e merged commit 2697fa7 into tokio-rs:master Aug 8, 2021
@stepancheg stepancheg deleted the put-bytes branch August 8, 2021 21:55
@Darksonn Darksonn mentioned this pull request Aug 25, 2021
lelongg pushed a commit to lelongg/bytes that referenced this pull request Jan 9, 2023
Equivalent to

```
for _ in 0..cnt {
    self.put_u8(val);
}
```

but may work faster.

Name and signature is chosen to be consistent with `ptr::write_bytes`.

Include three specializations:
* `Vec<u8>`
* `&mut [u8]`
* `BytesMut`

`BytesMut` and `&mut [u8]` specializations use `ptr::write`, `Vec<u8>`
specialization uses `Vec::resize`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants