Commit graph

105 commits

Author SHA1 Message Date
king6cong
3c56a65bc4 reuse capacity variable in slice::repeat 2019-12-24 12:44:05 +08:00
David Tolnay
1c4d453969
Format liballoc with rustfmt 2019-11-29 20:25:07 -08:00
Lzu Tao
4a2ae451e3 Stabilize slice::repeat (feature repeat_generic_slice) 2019-10-02 04:48:15 +00:00
Lzu Tao
6c1b447f2e Remove unneeded fn main blocks from docs 2019-10-01 11:55:46 +00:00
Simon Sapin
bbc9366c1a
Update src/liballoc/slice.rs
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-07-09 18:19:10 +02:00
Simon Sapin
d0635ee5f7
Update src/liballoc/slice.rs
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-07-09 18:19:01 +02:00
Simon Sapin
b62a77b490 Add joining slices of slices with a slice separator, not just a single item 2019-07-09 11:45:46 +02:00
Simon Sapin
283f6762ca Take separator by value in [T]::join 2019-07-09 11:45:46 +02:00
Simon Sapin
01d93bf595 Split the SliceConcat trait into Concat and Join 2019-07-09 11:45:46 +02:00
Simon Sapin
5397dfce77 Remove obsolete “should not have to exist” reasons 2019-07-09 11:45:46 +02:00
Simon Sapin
e808d921dd Replace SliceConcatExt trait with inherent methods and SliceConcat helper trait
Before this change `SliceConcatExt` was an unstable extension trait
with stable methods. It was in the libstd prelude, so that its methods
could be used on the stable channel.

This replaces it with inherent methods,
which can be used without any addition to the prelude.
Since the methods are stable and very generic
(with for example a return type that depends on the types of parameters),
an helper trait is still needed.
But now that trait does not need to be in scope for the methods to be used.

Removing this depedency on the libstd prelude allows the methods to be used
in `#![no_std]` crate that use liballoc, which does not have its own
implicitly-imported prelude.
2019-07-05 11:49:30 +02:00
Mazdak Farrokhzad
3a8536edef
Rollup merge of #61146 - czipperz:SliceConcatExt-connect-default-to-join, r=sfackler
SliceConcatExt::connect defaults to calling join

It makes sense to default a deprecated method to the new one.  Precedence example is `Error::cause` defaults to calling `Error::source`.
2019-06-22 01:42:30 +02:00
Ralf Jung
645f685e1b Box::into_vec: use Box::into_raw instead of mem::forget 2019-05-27 22:40:28 +02:00
Chris Gregory
3dd114e1cb SliceConcatExt::connect defaults to calling join 2019-05-24 21:04:56 -05:00
Alexander Regueiro
9f800457dd Ban multi-trait objects via trait aliases. 2019-05-20 16:12:49 +01:00
Ralf Jung
50c615baa2 warn(missing_docs) in liballoc, and add missing docs 2019-04-15 16:35:50 +02:00
Scott McMurray
317f15304e Revert "Remove mentions of unstable sort_by_cached key from stable documentation"
This reverts commit 9c7b69e179.
2019-02-12 22:26:44 -08:00
Scott McMurray
3777b86f9b Stabilize slice_sort_by_cached_key 2019-02-12 22:26:44 -08:00
Alexander Regueiro
99ed06eb88 libs: doc comments 2019-02-10 23:57:25 +00:00
Mazdak Farrokhzad
2396780cda liballoc: revert nested imports style changes. 2019-02-03 08:27:44 +01:00
Mazdak Farrokhzad
748970dfa9 liballoc: apply uniform_paths. 2019-02-02 11:05:20 +01:00
Mazdak Farrokhzad
3bfa0a35f6 liballoc: prefer imports of borrow from libcore. 2019-02-02 10:53:27 +01:00
Mazdak Farrokhzad
f09f62f62c liballoc: adjust abolute imports + more import fixes. 2019-02-02 10:34:36 +01:00
Mazdak Farrokhzad
7693e3e666 liballoc: refactor & fix some imports. 2019-02-02 10:14:40 +01:00
Mazdak Farrokhzad
e6e27924e1 liballoc: cargo check passes on 2018 2019-02-02 08:36:45 +01:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
bors
9cb38a84e7 Auto merge of #56463 - ljedrz:slice_concat_join, r=nikic
slice: tweak concat & join

- use `sum` instead of `fold` (readability)
- adjust the capacity for `join` - the number of separators is `n - 1`, not `n`; proof:
```
fn main() {
    let a = [[1, 2], [4, 5]];
    let v = a.join(&3);

    assert_ne!(v.len(), v.capacity()); // len is 5, capacity is 6
}
```
2018-12-09 22:39:44 +00:00
Alexander Regueiro
ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
ljedrz
ae53273021 slice: tweak concat & join 2018-12-03 16:22:27 +01:00
bors
f3adec65dd Auto merge of #53918 - Havvy:doc-sort-by, r=GuillaumeGomez
Doc total order requirement of sort(_unstable)_by

I took the definition of what a total order is from the Ord trait
docs. I specifically put "elements of the slice" because if you
have a slice of f64s, but know none are NaN, then sorting by
partial ord is total in this case. I'm not sure if I should give
such an example in the docs or not.

r? @GuillaumeGomez
2018-11-22 06:50:18 +00:00
Sebastian Dröge
52cc6fde4b Stabilize slice::rchunks(), rchunks_mut(), rchunks_exact(), rchunk_exact_mut()
Fixes #55177
2018-10-18 18:51:56 +03:00
Sebastian Dröge
b08ca2958e Stabilize slice::chunks_exact() and slice::chunks_exact_mut()
Fixes #47115
2018-10-18 18:51:56 +03:00
Sebastian Dröge
80a8e5c1f7 Add slice::rchunks(), rchunks_mut(), rchunks_exact() and rchunks_exact_mut()
These work exactly like the normal chunks iterators but start creating
chunks from the end of the slice.

See #55177 for the tracking issue
2018-10-18 10:38:05 +03:00
Havvy (Ryan Scheel)
99bed21101 Linkify types in docs 2018-10-05 17:41:43 -07:00
Havvy (Ryan Scheel)
b911dba40b Slice total example: Move closer to total defn 2018-10-05 17:41:43 -07:00
Havvy (Ryan Scheel)
e36bbc82f2 Example of total ord of elements for sort_by 2018-10-05 17:41:42 -07:00
Havvy (Ryan Scheel)
7e57f0a6a8 Doc total order requirement of sort(_unstable)_by
I took the definition of what a total order is from the Ord trait
docs. I specifically put "elements of the slice" because if you
have a slice of f64s, but know none are NaN, then sorting by
partial ord is total in this case. I'm not sure if I should give
such an example in the docs or not.
2018-10-05 17:41:42 -07:00
Sebastian Dröge
068c92b2cc Also rename ExactChunks iterator name to ChunksExact 2018-09-25 08:56:48 +03:00
Sebastian Dröge
e09e45041b Rename slice::exact_chunks() to slice::chunks_exact()
See https://github.com/rust-lang/rust/issues/47115#issuecomment-403090815
and https://github.com/rust-lang/rust/issues/47115#issuecomment-424053547
2018-09-24 22:43:06 +03:00
Alex Crichton
8ac88d375e std: Check for overflow in str::repeat
This commit fixes a buffer overflow issue in the standard library
discovered by Scott McMurray where if a large number was passed to
`str::repeat` it may cause and out of bounds write to the buffer of a `Vec`.
This bug was accidentally introduced in #48657 when optimizing the
`str::repeat` function. The bug affects stable Rust releases 1.26.0 to
1.29.0. We plan on backporting this fix to create a 1.29.1 release, and
the 1.30.0 release onwards will include this fix.

The fix in this commit is to introduce a deterministic panic in the case of
capacity overflow. When repeating a slice where the resulting length is larger
than the address space, there’s no way it can succeed anyway!

The standard library and surrounding libraries were briefly checked to see if
there were othere instances of preallocating a vector with a calculation that
may overflow. No instances of this bug (out of bounds write due to a calculation
overflow) were found at this time.

Note that this commit is the first steps towards fixing this issue,
we'll be making a formal post to the Rust security list once these
commits have been merged.
2018-09-20 09:31:53 -07:00
Corey Farwell
993fb93464 Replace usages of ptr::offset with ptr::{add,sub}. 2018-08-20 07:28:34 -04:00
Mark Simulacrum
5a575b542d
Rollup merge of #51147 - tmccombs:sliceindex, r=SimonSapin
Stabilize SliceIndex trait.

CC #35729

According to recommendations in
https://github.com/rust-lang/rust/issues/35729#issuecomment-377784884
2018-06-02 13:14:25 -06:00
Emerentius
12bd288746 incorporate changes from code review
further reduce unsafe fn calls
reduce right drift
assert! sufficient capacity
2018-06-01 17:13:26 +02:00
Emerentius
d866082050 optimize joining and concatenation for slices
for both Vec<T> and String
- eliminates the boolean first flag in fn join()

for String only
- eliminates repeated bounds checks in join(), concat()
- adds fast paths for small string separators up to a len of 4 bytes
2018-06-01 17:13:24 +02:00
Thayne McCombs
9d770e9959 Stabilize SliceIndex trait.
Fixes #35729

According to recommendations in
https://github.com/rust-lang/rust/issues/35729#issuecomment-377784884
2018-06-01 00:04:26 -06:00
Stjepan Glavina
26d62f55a4 Stabilize feature from_ref 2018-05-21 18:16:08 +02:00
Mark Simulacrum
9e3432447a Switch to 1.26 bootstrap compiler 2018-05-17 08:47:25 -06:00
Michael Lamparski
8010604b2d move See also links to top 2018-05-09 18:30:32 -04:00
bors
f305b025cf Auto merge of #48999 - GuillaumeGomez:add-repeat-on-slice, r=Kimundi
Add repeat method on slice

Fixes #48784.
2018-04-24 03:31:11 +00:00
Simon Sapin
90f29fbdb1 Replace SliceExt with inherent [T] methods in libcore 2018-04-21 09:45:18 +02:00