about summary refs log tree commit diff
path: root/src/libcollections/vec.rs
AgeCommit message (Collapse)AuthorLines
2014-12-08auto merge of #19574 : erickt/rust/vec-reserve, r=alexcrichtonbors-4/+5
(I don't understand why this works, and so I don't quite trust this yet. I'm pushing it up to see if anyone else can replicate this performance increase) Somehow llvm is able to optimize this version of Vec::reserve into dramatically faster than the old version. In micro-benchmarks this was 2-10 times faster. It also reduce my Rust compile time from 41 minutes to 27 minutes. Closes #19281.
2014-12-08auto merge of #19306 : steveklabnik/rust/gh19269, r=nikomatsakis,brsonbors-8/+2
Fixes #19269. /cc @thestinger @mahkoh @mitsuhiko
2014-12-06libcollections: remove unnecessary `as_mut_slice()` callsJorge Aparicio-6/+6
2014-12-06libcollections: remove unnecessary `as_slice()` callsJorge Aparicio-9/+8
2014-12-05collections: dramatically speed up Vec::reserve with magicErick Tryzelaar-4/+5
Somehow llvm is able to optimize this version of Vec::reserve into dramatically faster than the old version. In micro-benchmarks this was 2-10 times faster. It also shaved 14 minutes off of rust's compile times. Closes #19281.
2014-12-03Deprecate EquivJorge Aparicio-1/+2
2014-12-03Fix falloutJorge Aparicio-4/+4
2014-12-03Overload the `==` operatorJorge Aparicio-4/+59
- String == &str == CowString - Vec == &[T] == &mut [T] == [T, ..N] == CowVec - InternedString == &str
2014-11-29Add test for #18908Tobias Bucher-0/+29
2014-11-26rollup merge of #19308: thestinger/oomAlex Crichton-0/+1
Closes #19305
2014-11-26auto merge of #19176 : aturon/rust/stab-iter, r=alexcrichtonbors-1/+1
This is an initial pass at stabilizing the `iter` module. The module is fairly large, but is also pretty polished, so most of the stabilization leaves things as they are. Some changes: * Due to the new object safety rules, various traits needs to be split into object-safe traits and extension traits. This includes `Iterator` itself. While splitting up the traits adds some complexity, it will also increase flexbility: once we have automatic impls of `Trait` for trait objects over `Trait`, then things like the iterator adapters will all work with trait objects. * Iterator adapters that use up the entire iterator now take it by value, which makes the semantics more clear and helps catch bugs. Due to the splitting of Iterator, this does not affect trait objects. If the underlying iterator is still desired for some reason, `by_ref` can be used. (Note: this change had no fallout in the Rust distro except for the useless mut lint.) * In general, extension traits new and old are following an [in-progress convention](rust-lang/rfcs#445). As such, they are marked `unstable`. * As usual, anything involving closures is `unstable` pending unboxed closures. * A few of the more esoteric/underdeveloped iterator forms (like `RandomAccessIterator` and `MutableDoubleEndedIterator`, along with various unfolds) are left experimental for now. * The `order` submodule is left `experimental` because it will hopefully be replaced by generalized comparison traits. * "Leaf" iterators (like `Repeat` and `Counter`) are uniformly constructed by free fns at the module level. That's because the types are not otherwise of any significance (if we had `impl Trait`, you wouldn't want to define a type at all). Closes #17701 Due to renamings and splitting of traits, this is a: [breaking-change]
2014-11-25Fallout from stabilizationAaron Turon-1/+1
2014-11-25Deprecate MaybeOwned[Vector] in favor of CowJorge Aparicio-0/+22
2014-11-25vec: add missing out-of-memory checkDaniel Micay-0/+1
Closes #19305
2014-11-25Update documentation for from_raw_partsSteve Klabnik-8/+2
Fixes #19269.
2014-11-23Rename unwrap functions to into_innerAlex Crichton-1/+5
This change applies the conventions to unwrap listed in [RFC 430][rfc] to rename non-failing `unwrap` methods to `into_inner`. This is a breaking change, but all `unwrap` methods are retained as `#[deprecated]` for the near future. To update code rename `unwrap` method calls to `into_inner`. [rfc]: https://github.com/rust-lang/rfcs/pull/430 [breaking-change] Closes #13159 cc #19091
2014-11-23auto merge of #19152 : alexcrichton/rust/issue-17863, r=aturonbors-9/+19
This commit is an implementation of [RFC 240][rfc] when applied to the standard library. It primarily deprecates the entirety of `string::raw`, `vec::raw`, `slice::raw`, and `str::raw` in favor of associated functions, methods, and other free functions. The detailed renaming is: * slice::raw::buf_as_slice => slice::from_raw_buf * slice::raw::mut_buf_as_slice => slice::from_raw_mut_buf * slice::shift_ptr => deprecated with no replacement * slice::pop_ptr => deprecated with no replacement * str::raw::from_utf8 => str::from_utf8_unchecked * str::raw::c_str_to_static_slice => str::from_c_str * str::raw::slice_bytes => deprecated for slice_unchecked (slight semantic diff) * str::raw::slice_unchecked => str.slice_unchecked * string::raw::from_parts => String::from_raw_parts * string::raw::from_buf_len => String::from_raw_buf_len * string::raw::from_buf => String::from_raw_buf * string::raw::from_utf8 => String::from_utf8_unchecked * vec::raw::from_buf => Vec::from_raw_buf All previous functions exist in their `#[deprecated]` form, and the deprecation messages indicate how to migrate to the newer variants. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0240-unsafe-api-location.md [breaking-change] Closes #17863
2014-11-22std: Align `raw` modules with unsafe conventionsAlex Crichton-9/+19
This commit is an implementation of [RFC 240][rfc] when applied to the standard library. It primarily deprecates the entirety of `string::raw`, `vec::raw`, `slice::raw`, and `str::raw` in favor of associated functions, methods, and other free functions. The detailed renaming is: * slice::raw::buf_as_slice => slice::with_raw_buf * slice::raw::mut_buf_as_slice => slice::with_raw_mut_buf * slice::shift_ptr => deprecated with no replacement * slice::pop_ptr => deprecated with no replacement * str::raw::from_utf8 => str::from_utf8_unchecked * str::raw::c_str_to_static_slice => str::from_c_str * str::raw::slice_bytes => deprecated for slice_unchecked (slight semantic diff) * str::raw::slice_unchecked => str.slice_unchecked * string::raw::from_parts => String::from_raw_parts * string::raw::from_buf_len => String::from_raw_buf_len * string::raw::from_buf => String::from_raw_buf * string::raw::from_utf8 => String::from_utf8_unchecked * vec::raw::from_buf => Vec::from_raw_buf All previous functions exist in their `#[deprecated]` form, and the deprecation messages indicate how to migrate to the newer variants. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0240-unsafe-api-location.md [breaking-change] Closes #17863
2014-11-21auto merge of #18908 : tbu-/rust/pr_mapinplace_fixzerosized, r=alexcrichtonbors-1/+4
2014-11-20libcore: DST-ify AsSliceAaron Turon-2/+3
This commit changes `AsSlice` to work on unsized types, and changes the `impl` for `&[T]` to `[T]`. Aside from making the trait more general, this also helps some ongoing work with method resolution changes. This is a breaking change: code that uses generics bounded by `AsSlice` will have to change. In particular, such code previously often took arguments of type `V` where `V: AsSlice<T>` by value. These should now be taken by reference: ```rust fn foo<Sized? V: AsSlice<T>>(v: &V) { .. } ``` A few std lib functions have been changed accordingly. [breaking-change]
2014-11-17Fix fallout from coercion removalNick Cameron-8/+8
2014-11-16rollup merge of #18976: bjz/rfc369-numericsJakub Bukaj-0/+7
2014-11-16rollup merge of #18970: aturon/fixup-stableJakub Bukaj-1/+0
2014-11-16Move ToString to collections::stringBrendan Zabarauskas-0/+7
This also impls `FormatWriter` for `Vec<u8>`
2014-11-14libs: fix #[stable] inheritance falloutAaron Turon-1/+0
A recent change turned off inheritance for the #[stable] by default, but failed to catch all the cases where this was being used in std. This patch fixes that problem.
2014-11-14auto merge of #18880 : barosl/rust/doc-fail-to-panic, r=alexcrichtonbors-4/+4
I found some occurrences of "failure" and "fails" in the documentation. I changed them to "panics" if it means a task panic. Otherwise I left it as is, or changed it to "errors" to clearly distinguish them. Also, I made a minor fix that is breaking the layout of a module page. "Example" is shown in an irrelevant place from the following page: http://doc.rust-lang.org/std/os/index.html
2014-11-14auto merge of #18827 : bjz/rust/rfc369-numerics, r=alexcrichtonbors-7/+7
This implements a considerable portion of rust-lang/rfcs#369 (tracked in #18640). Some interpretations had to be made in order to get this to work. The breaking changes are listed below: [breaking-change] - `core::num::{Num, Unsigned, Primitive}` have been deprecated and their re-exports removed from the `{std, core}::prelude`. - `core::num::{Zero, One, Bounded}` have been deprecated. Use the static methods on `core::num::{Float, Int}` instead. There is no equivalent to `Zero::is_zero`. Use `(==)` with `{Float, Int}::zero` instead. - `Signed::abs_sub` has been moved to `std::num::FloatMath`, and is no longer implemented for signed integers. - `core::num::Signed` has been removed, and its methods have been moved to `core::num::Float` and a new trait, `core::num::SignedInt`. The methods now take the `self` parameter by value. - `core::num::{Saturating, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv}` have been removed, and their methods moved to `core::num::Int`. Their parameters are now taken by value. This means that - `std::time::Duration` no longer implements `core::num::{Zero, CheckedAdd, CheckedSub}` instead defining the required methods non-polymorphically. - `core::num::{zero, one, abs, signum}` have been deprecated. Use their respective methods instead. - The `core::num::{next_power_of_two, is_power_of_two, checked_next_power_of_two}` functions have been deprecated in favor of methods defined a new trait, `core::num::UnsignedInt` - `core::iter::{AdditiveIterator, MultiplicativeIterator}` are now only implemented for the built-in numeric types. - `core::iter::{range, range_inclusive, range_step, range_step_inclusive}` now require `core::num::Int` to be implemented for the type they a re parametrized over.
2014-11-12Fix `Vec::map_in_place` not doing what is written in the commentTobias Bucher-1/+4
2014-11-12Register new snapshotsAlex Crichton-14/+0
2014-11-13Remove lots of numeric traits from the preludesBrendan Zabarauskas-1/+1
Num, NumCast, Unsigned, Float, Primitive and Int have been removed.
2014-11-13Move checked arithmetic operators into Int traitBrendan Zabarauskas-5/+5
2014-11-13Create UnsignedInt trait and deprecate free functionsBrendan Zabarauskas-2/+2
2014-11-12Fix remaining documentation to reflect fail!() -> panic!()Barosl Lee-4/+4
Throughout the docs, "failure" was replaced with "panics" if it means a task panic. Otherwise, it remained as is, or changed to "errors" to clearly differentiate it from a task panic.
2014-11-08auto merge of #18475 : gamazeps/rust/toExtend, r=alexcrichtonbors-2/+2
Ensured that Extend & FromIterator are implemented for the libcollection. Removed the fact that FromIterator had to be implemented in order to implement Extend, as it did not make sense for LruCache (it needs to be given a size and there are no Default for LruCache). Changed the name from Extend to Extendable. Part of #18424
2014-11-08Renamed Extendable to Extendgamazeps-2/+2
In order to upgrade, simply rename the Extendable trait to Extend in your code Part of #18424 [breaking-change]
2014-11-07Remove unnecessary `.to_string()`s from `Vec.swap_remove`'s doc example.Utkarsh Kukreti-6/+5
2014-11-06rollup merge of #18605 : Gankro/collect-fruitAlex Crichton-77/+74
2014-11-06Implement low-hanging fruit of collection conventionsAlexis Beingessner-77/+74
* Renames/deprecates the simplest and most obvious methods * Adds FIXME(conventions)s for outstanding work * Marks "handled" methods as unstable NOTE: the semantics of reserve and reserve_exact have changed! Other methods have had their semantics changed as well, but in a way that should obviously not typecheck if used incorrectly. Lots of work and breakage to come, but this handles most of the core APIs and most eggregious breakage. Future changes should *mostly* focus on niche collections, APIs, or simply back-compat additions. [breaking-change]
2014-11-06Prelude: rename and consolidate extension traitsAaron Turon-2/+2
This commit renames a number of extension traits for slices and string slices, now that they have been refactored for DST. In many cases, multiple extension traits could now be consolidated. Further consolidation will be possible with generalized where clauses. The renamings are consistent with the [new `-Prelude` suffix](https://github.com/rust-lang/rfcs/pull/344). There are probably a few more candidates for being renamed this way, but that is left for API stabilization of the relevant modules. Because this renames traits, it is a: [breaking-change] However, I do not expect any code that currently uses the standard library to actually break. Closes #17917
2014-11-05Fix fallout of DSTifying PartialEq, PartialOrd, Eq, OrdJorge Aparicio-0/+14
2014-11-05Add impls of the comparison operators for fixed-length arrays of lengths ↵Niko Matsakis-3/+3
0...32 and repair various cases where slices and fixed-length arrays were being compared.
2014-11-05Repair various cases where values of distinct types were being operatedNiko Matsakis-1/+1
upon (e.g., `&int` added to `int`).
2014-11-01bubble up out-of-memory errors from liballocDaniel Micay-0/+3
This makes the low-level allocation API suitable for use cases where out-of-memory conditions need to be handled. Closes #18292 [breaking-change]
2014-11-01collections: Remove all collections traitsAlex Crichton-71/+96
As part of the collections reform RFC, this commit removes all collections traits in favor of inherent methods on collections themselves. All methods should continue to be available on all collections. This is a breaking change with all of the collections traits being removed and no longer being in the prelude. In order to update old code you should move the trait implementations to inherent implementations directly on the type itself. Note that some traits had default methods which will also need to be implemented to maintain backwards compatibility. [breaking-change] cc #18424
2014-10-30rollup merge of #18445 : alexcrichton/index-mutAlex Crichton-12/+4
Conflicts: src/libcollections/vec.rs
2014-10-30rollup merge of #18443 : alexcrichton/deref-vec-and-stringAlex Crichton-363/+20
2014-10-30collections: Enable IndexMut for some collectionsAlex Crichton-12/+4
This commit enables implementations of IndexMut for a number of collections, including Vec, RingBuf, SmallIntMap, TrieMap, TreeMap, and HashMap. At the same time this deprecates the `get_mut` methods on vectors in favor of using the indexing notation. cc #18424
2014-10-29collections: impl Deref for Vec/StringAlex Crichton-363/+20
This commit adds the following impls: impl<T> Deref<[T]> for Vec<T> impl<T> DerefMut<[T]> for Vec<T> impl Deref<str> for String This commit also removes all duplicated inherent methods from vectors and strings as implementations will now silently call through to the slice implementation. Some breakage occurred at std and beneath due to inherent methods removed in favor of those in the slice traits and std doesn't use its own prelude, cc #18424
2014-10-29Rename fail! to panic!Steve Klabnik-21/+21
https://github.com/rust-lang/rfcs/pull/221 The current terminology of "task failure" often causes problems when writing or speaking about code. You often want to talk about the possibility of an operation that returns a Result "failing", but cannot because of the ambiguity with task failure. Instead, you have to speak of "the failing case" or "when the operation does not succeed" or other circumlocutions. Likewise, we use a "Failure" header in rustdoc to describe when operations may fail the task, but it would often be helpful to separate out a section describing the "Err-producing" case. We have been steadily moving away from task failure and toward Result as an error-handling mechanism, so we should optimize our terminology accordingly: Result-producing functions should be easy to describe. To update your code, rename any call to `fail!` to `panic!` instead. Assuming you have not created your own macro named `panic!`, this will work on UNIX based systems: grep -lZR 'fail!' . | xargs -0 -l sed -i -e 's/fail!/panic!/g' You can of course also do this by hand. [breaking-change]
2014-10-28auto merge of #18254 : areski/rust/pr-fix-vec-doc-example, r=alexcrichtonbors-2/+8
- shrink_to_fit example is now more clear by asserting the capacity value - annotation [0, mid) changed for [0, mid]