diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2020-05-30 12:39:10 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-30 12:39:10 +0900 |
| commit | 3459eae96c3ab9ae40012e97723c7550e96200f6 (patch) | |
| tree | 50915fa5c4f97e213425d8abed679d7c016db0fb /src/libstd/sys_common | |
| parent | a578ac52bafef5b2a270fddfd36870c9c7fc862e (diff) | |
| parent | a51b22a9fda2fff37b17ad7b7fa516b3385089a9 (diff) | |
| download | rust-3459eae96c3ab9ae40012e97723c7550e96200f6.tar.gz rust-3459eae96c3ab9ae40012e97723c7550e96200f6.zip | |
Rollup merge of #72162 - cuviper:extend_one, r=Mark-Simulacrum
Add Extend::{extend_one,extend_reserve}
This adds new optional methods on `Extend`: `extend_one` add a single
element to the collection, and `extend_reserve` pre-allocates space for
the predicted number of incoming elements. These are used in `Iterator`
for `partition` and `unzip` as they shuffle elements one-at-a-time into
their respective collections.
Diffstat (limited to 'src/libstd/sys_common')
| -rw-r--r-- | src/libstd/sys_common/wtf8.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libstd/sys_common/wtf8.rs b/src/libstd/sys_common/wtf8.rs index a98407da448..a5ba3daba3e 100644 --- a/src/libstd/sys_common/wtf8.rs +++ b/src/libstd/sys_common/wtf8.rs @@ -386,6 +386,17 @@ impl Extend<CodePoint> for Wtf8Buf { self.bytes.reserve(low); iterator.for_each(move |code_point| self.push(code_point)); } + + #[inline] + fn extend_one(&mut self, code_point: CodePoint) { + self.push(code_point); + } + + #[inline] + fn extend_reserve(&mut self, additional: usize) { + // Lower bound of one byte per code point (ASCII only) + self.bytes.reserve(additional); + } } /// A borrowed slice of well-formed WTF-8 data. |
