Commit Graph

81 Commits

Author SHA1 Message Date
Pietro Albini e9e92d53ad Rollup merge of #56548 - Lucretiel:string-extend-optimize, r=sfackler
Optimized string FromIterator + Extend impls

I noticed that there was a lost opportunity to reuse string buffers in `FromIterator<String>` and `FromIterator<Cow<str>>`; updated the implementations to use these. In practice this translates to at least one fewer allocation when using these APIs.

Additionally, rewrote `Extend` implementations to use `iter.for_each`, which (supposedly) helps the compiler optimize those loops (because iterator adapters are encouraged to provide optimized implementations of `fold` and `try_fold`.
2018-12-06 07:49:01 +01:00
Nathan West 811a2bfe53 Added explainatory comments 2018-12-05 17:46:03 -08:00
Nathan West 823dd8ca33 Fixed mutability 2018-12-05 15:11:32 -08:00
Nathan West 180dcc3118 Optimized string FromIterator impls 2018-12-05 14:51:04 -08:00
ljedrz d0c64bb296 cleanup: remove static lifetimes from consts 2018-12-04 12:46:10 +01:00
Hidehito Yabuuchi 1e18cc916f Update issue number of shrink_to methods to point the tracking issue 2018-12-02 16:08:08 +09:00
ljedrz 591607d237 String: add a FIXME to from_utf16 2018-11-21 10:17:54 +01:00
Pietro Albini 3b40434940 Rollup merge of #55530 - ljedrz:speed_up_String_from_utf16, r=SimonSapin
Speed up String::from_utf16

Collecting into a `Result` is idiomatic, but not necessarily fast due to rustc not being able to preallocate for the resulting collection. This is fine in case of an error, but IMO we should optimize for the common case, i.e. a successful conversion.

This changes the behavior of `String::from_utf16` from collecting into a `Result` to pushing to a preallocated `String` in a loop.

According to [my simple benchmark](https://gist.github.com/ljedrz/953a3fb74058806519bd4d640d6f65ae) this change makes `String::from_utf16` around **twice** as fast.
2018-11-15 11:04:31 +01:00
Denis Vasilik 6f3add34ca Minor style guide corrections. 2018-11-11 20:11:25 +01:00
Denis Vasilik dc0fd65af2 Whitespace cleanup according to Rust's style guidelines. 2018-11-11 16:58:00 +01:00
Denis Vasilik f0bfbd3e72 Added comments for trait implementations. 2018-11-11 15:44:15 +01:00
Denis Vasilik 93b5112c16 Added comment for From trait implementation: boxed string slice to String 2018-11-11 15:43:43 +01:00
kennytm 9d9146ad95 Rollup merge of #55734 - teresy:shorthand-fields, r=davidtwco
refactor: use shorthand fields

refactor: use shorthand for single fields everywhere (excluding tests).
2018-11-07 21:27:00 +08:00
teresy eca11b99a7 refactor: use shorthand fields 2018-11-06 15:05:44 -05:00
ljedrz 19aa10132c Speed up String::from_utf16 2018-10-31 10:22:22 +01:00
Hsiang-Cheng Yang 4cb611f3d1 Update string.rs
remove unused variable i in example String::with_capacity()
2018-10-27 14:33:07 +08:00
Matthias Krüger d24070bf8d liballoc: mark str.to_owned() and String::from(&str) as #[inline].
Fixes #53681
2018-09-27 12:08:03 +02:00
Guillaume Gomez c1ad1b0338 Fix invalid urls 2018-09-06 23:32:30 +02:00
Matthias Krüger 11f3918ca2 docs: std::string::String.repeat(): slightly rephrase to be more in-line with other descriptions.
add ticks around a few keywords in other descriptions.
2018-08-22 08:35:34 +02:00
Corey Farwell 993fb93464 Replace usages of ptr::offset with ptr::{add,sub}. 2018-08-20 07:28:34 -04:00
Corey Farwell ec18991492 Add links to std::char::REPLACEMENT_CHARACTER from docs.
There are a few places where we mention the replacement character in the
docs, and it could be helpful for users to utilize the constant which is
available in the standard library, so let’s link to it!
2018-08-11 15:42:35 -04:00
kennytm 67cf3ba528 Rollup merge of #51807 - newpavlov:deprecate_str_slice, r=alexcrichton
Deprecation of str::slice_unchecked(_mut)

Closes #51715

I am not sure if 1.28.0 or 1.29.0 should be used for deprecation version, for now it's 1.28.0.

Additionally I've replaced `slice_unchecked` uses with `get_unchecked`. The only places where this method is still used are `src/liballoc/tests/str.rs` and `src/liballoc/tests/str.rs`.
2018-07-22 22:10:09 +08:00
Simon Sapin b0547cea0a Move core::alloc::CollectionAllocErr to alloc::collections 2018-06-29 14:01:33 +02:00
newpavlov 7c316090eb Deprecation of str::slice_uncheked(_mut) 2018-06-26 13:34:42 +03:00
Cory Sherman 1440f300d8 stabilize RangeBounds collections_range #30877
rename RangeBounds::start() -> start_bound()
rename RangeBounds::end() -> end_bound()
2018-05-24 05:01:40 -07:00
kennytm 8366780164 Rollup merge of #50170 - burtonageo:more_cow_from, r=alexcrichton
Implement From for more types on Cow

This is basically https://github.com/rust-lang/rust/pull/48191, except that it should be implemented in a way that doesn't break third party crates.
2018-05-17 05:22:07 +08:00
George Burton 17e262880c Update features to 1.28.0 2018-05-09 07:23:02 +01:00
F001 160063aad2 make String::new() const 2018-05-05 16:38:27 +08:00
George Burton f3e858aae7 Update the stable attributes to use the current nightly version number 2018-04-27 20:46:06 +01:00
George Burton 1133a149f1 Implement From for more types on Cow 2018-04-22 22:57:52 +01:00
Corey Farwell 01e8bebaf1 Remove no longer necessary comparison to Vec::splice.
`String::replace_range` was previously called `String::splice`, so this
note was necessary to differentiate it from the `Vec` method. Now that
it's renamed, this note no longer seems necessary.
2018-04-17 10:23:06 +09:00
kennytm bf60295211 Rollup merge of #49555 - nox:inline-into-boxed, r=alexcrichton
Inline most of the code paths for conversions with boxed slices

This helps with the specific problem described in #49541, obviously without making any large change to how inlining works in the general case.

Everything involved in the conversions is made `#[inline]`, except for the `<Vec<T>>::into_boxed_slice` entry point which is made `#[inline(always)]` after checking that duplicating the function mentioned in the issue prevented its inlining if I only annotate it with
`#[inline]`.

For the record, that function was:

```rust
pub fn foo() -> Box<[u8]> {
    vec![0].into_boxed_slice()
}
```

To help the inliner's job, we also hoist a `self.capacity() != self.len` check in `<Vec<T>>::shrink_to_fit` and mark it as `#[inline]` too.
2018-04-17 01:50:56 +08:00
Mike Hommey bd9ff8476d Cleanup liballoc use statements
Some modules were still using the deprecated `allocator` module, use the
`alloc` module instead.

Some modules were using `super` while it's not needed.

Some modules were more or less ordering them, and other not, so the
latter have been modified to match the others.
2018-04-14 08:43:13 +09:00
Simon Sapin 939692409d Reexport from core::unicode::char in core::char rather than vice versa 2018-04-12 00:13:52 +02:00
Simon Sapin b2027ef17c Deprecate the std_unicode crate 2018-04-12 00:13:51 +02:00
Simon Sapin f87d4a15a8 Move Utf8Lossy decoder to libcore 2018-04-12 00:13:43 +02:00
Thayne McCombs 196b1426be Stabilize String::replace_range
Fixes #44643
2018-04-01 22:50:22 -06:00
Anthony Ramine 360f2f036d Inline most of the code paths for conversions with boxed slices
This helps with the specific problem described in #49541, obviously without
making any large change to how inlining works in the general case.

Everything involved in the conversions is made `#[inline]`, except for the
`<Vec<T>>::into_boxed_slice` entry point which is made `#[inline(always)]`
after checking that duplicating the function mentioned in the issue prevented
its inlining if I only annotate it with `#[inline]`.

For the record, that function was:

```rust
pub fn foo() -> Box<[u8]> {
    vec![0].into_boxed_slice()
}
```

To help the inliner's job, we also hoist a `self.capacity() != self.len` check
in `<Vec<T>>::shrink_to_fit` and mark it as `#[inline]` too.
2018-04-01 11:56:23 +02:00
Simon Sapin 16d3ba1b23 Move RangeArguments to {core::std}::ops and rename to RangeBounds
These unstable items are deprecated:

* The `std::collections::range::RangeArgument` reexport
* The `std::collections::range` module.
2018-03-29 13:12:49 +02:00
Simon Sapin c3a63970de Move alloc::Bound to {core,std}::ops
The stable reexport `std::collections::Bound` is now deprecated.

Another deprecated reexport could be added in `alloc`,
but that crate is unstable.
2018-03-29 13:12:49 +02:00
kennytm 010fb40b44 Rollup merge of #49400 - Diggsey:shrink-to, r=joshtriplett
Implement `shrink_to` method on collections

Fixes #49385
2018-03-28 17:55:09 +02:00
kennytm 43f56ce131 Rollup merge of #49243 - murarth:stabilize-retain, r=BurntSushi
Stabilize method `String::retain`

Closes #43874
2018-03-28 17:55:05 +02:00
Diggory Blake 04f6692aaf Implement shrink_to method on collections 2018-03-27 01:39:11 +01:00
Murarth 7c442e5c9b Stabilize method String::retain 2018-03-21 15:36:50 -07:00
varkor b57ea56159 Stabilise FromUtf8Error::as_bytes
Closes #40895.
2018-03-17 21:41:14 +00:00
bors 3926453944 Auto merge of #47813 - kennytm:stable-incl-range, r=nrc
Stabilize inclusive range (`..=`)

Stabilize the followings:

* `inclusive_range` — The `std::ops::RangeInclusive` and `std::ops::RangeInclusiveTo` types, except its fields (tracked by #49022 separately).
* `inclusive_range_syntax` — The `a..=b` and `..=b` expression syntax
* `dotdoteq_in_patterns` — Using `a..=b` in a pattern

cc #28237
r? @rust-lang/lang
2018-03-15 16:00:40 +00:00
kennytm b5913f2e76 Stabilize inclusive_range library feature.
Stabilize std::ops::RangeInclusive and std::ops::RangeInclusiveTo.
2018-03-15 16:58:01 +08:00
snf 92bfcd2b19 implementing fallible allocation API (try_reserve) for Vec, String and HashMap 2018-03-14 03:48:42 -07:00
Ulrik Sverdrup c7c23fe948 core: Update stability attributes for FusedIterator 2018-03-03 14:23:05 +01:00
Ulrik Sverdrup bc651cac8d core: Stabilize FusedIterator
FusedIterator is a marker trait that promises that the implementing
iterator continues to return `None` from `.next()` once it has returned
`None` once (and/or `.next_back()`, if implemented).

The effects of FusedIterator are already widely available through
`.fuse()`, but with stable `FusedIterator`, stable Rust users can
implement this trait for their iterators when appropriate.
2018-03-03 14:14:03 +01:00