Commit Graph

137 Commits

Author SHA1 Message Date
bluss f2aad9f9a7 API: Update ArrayExt's methods to expose slices instead of pointers
This is a nicer and simpler interface to expose, since the ref to uninit
array to pointer cast is not usable anyway (it's historic now, arrayvec
itself does not use it anymore).
2019-09-01 14:47:44 +02:00
bluss 2a3397995d FIX: Fix .extend() for ArrayVec with zero-sized type elements
The raw pointer walk did not do the right thing for ZST, because when
offsets are zero, the start and end pointer would be the same and the
loop ends before incrementing the length correctly.
2019-09-01 14:07:58 +02:00
bluss e68c0c7b48 Merge branch '0.4' into master
* 0.4:
  0.4.11
  TEST: Update tests for new MaybeUninit usage
  FEAT: Use stable MaybeUninit when we can (feature detected)
2019-07-10 17:51:59 +02:00
bluss b56c3b78d0 FEAT: Use stable MaybeUninit when we can (feature detected) 2019-07-10 16:40:50 +02:00
Tobias Bucher 76e89544a5 Merge pull request #124 from seanchen1991/master
Add semicolon to return statement for consistency
2019-06-21 02:24:36 +02:00
Sean Chen aab420b2ec Add semicolon to return statement for consistency 2019-06-20 14:36:13 -07:00
Jan-Erik Rediger 841ca1492b Fix word duplication in docs 2019-04-22 14:29:08 +02:00
bluss 74745a9756 DOC: Update minimum rust requirement to Rust 1.24
Rust 1.24 is on debian stable. It is compatible with crossbeam (Rust 1.26),
the rdep with most downloads.
2018-12-18 21:40:39 +01:00
bluss c4cd63209f FEAT: Use a separate union MaybeUninitCopy for ArrayString
This is the "real" union solution, and ArrayString can use it since its
backing array is Copy. Unfortunately, we'll have to use the Copy bound
on the type, making it "viral" and visible in the user API.
2018-12-16 18:32:14 +01:00
bluss 784ccc97ca DOC: Remove warning on ArrayVec's into_inner method 2018-12-16 18:32:14 +01:00
bluss 94ab27a649 Merge branch '0.4' of https://github.com/bluss/arrayvec into merge-0.4
* '0.4' of https://github.com/bluss/arrayvec:
  0.4.9
  TEST: Add test that ensures the MaybeUninit impl is used on nightly
  FIX: Remove use of uninitialized in ArrayString
  FEAT: Implement a "MaybeUninit" and use it conditionally
  TEST: Add test that Some(ArrayVec<[&_;_]>).is_some()
  MAINT: Test the 0.4 branch in travis
2018-12-16 18:09:20 +01:00
bluss d395a01e7c FIX: Remove use of uninitialized in ArrayString
We can't fix this properly (MaybeUninit with a union) until we change
the user visible API (we need to require that A: Copy.

As a temporary solution for arrayvec version 0.4.*, we use zeroed to
initialize an array of bytes, instead of using uninitialized. This may
have a negative performance impact, but the fix is to upgrade to future
arrayvec 0.5.
2018-12-15 15:12:03 +01:00
bluss 29012231a8 FEAT: Implement a "MaybeUninit" and use it conditionally
Use a build script to detect if we can use MaybeUninit or NoDrop.
Enabling unstable features automatically is not ideal, but since it's
a soundness issue we should do it.

Use a MaybeUninit-like union on nightly when we can. We use a feature
detection script in build.rs, so that we also go back to the fallback if
the unstable feature changes in an unexpected way.

We need to continue to use NoDrop for best working stable
implementation, but we eagerly use our union solution where we can,
currently only in nightlies.

Rustc feature probe code written by Josh Stone (cuviper),
taken from num-bigint.
2018-12-15 15:12:03 +01:00
bluss fd98c6647d FEAT: Improved extend performance 2018-11-28 16:04:05 +01:00
bluss 47827e4843 FIX: Remake extend_from_slice to try_extend_from_slice
Do nothing and return an error, if the slice doesn't fit in the
remaining capacity.
2018-11-28 15:59:11 +01:00
bluss 8e5ff2d0fb FIX: Rename ArrayVec .capacity_left() → .remaining_capacity() 2018-11-28 15:52:46 +01:00
Thomas de Zeeuw c4b6e86211 REFAC: use extend_from_slice in Write implementation for ArrayVec 2018-11-26 12:59:30 +01:00
Thomas de Zeeuw 2120e4bb75 FEAT: Add ArrayVec.extend_from_slice 2018-11-26 12:59:30 +01:00
Thomas de Zeeuw d11c853346 FEAT: Add ArrayVec.capacity_left 2018-11-26 12:59:30 +01:00
bluss f40e708f7c FIX: In truncate, don't access self while holding raw pointer derived from self
Again, stacked borrows model makes the `self.set_len()` call illegal
because we are holding (and are going to use) another raw pointer
derived from self, `tail`.
2018-11-25 16:37:29 +01:00
bluss 91e88a4976 FEAT: Simplify stack guard in extend
This simplification -- borrowing self.len instead of self, leads to
an improvement in the extend_from_slice benchmark.

It's also guided by the discussion of stacked borrows; the old code
would be invalid, because the whole self is borrowed while ptr is derived from
self.
2018-11-25 16:33:07 +01:00
bluss 233df73ab2 Merge pull request #98 from bluss/use-drop-in-place
Use drop_in_place for truncate and clear (and drop)
2018-11-25 10:40:17 +01:00
bluss 50728e4cda DOC: Add doc for additional array features flags 2018-11-25 09:24:16 +01:00
Clar Fon 46b64537cb Implement Clone, Debug for IntoIter 2018-10-28 18:45:11 -04:00
bluss 9db64d5948 FIX: Fix a typo in a comment 2018-03-25 23:26:20 +02:00
bluss 602e55dc67 FEAT: Use drop_in_place for truncate and clear (and drop)
This should perform better in both release and debug mode.

NOTE: This is significant because it changes the drop order of the
elements, and how we handle panicking destructors. If just one of the
destructors panic during ArrayVec drop, clear or truncate, the rest of
the elements should still drop. If we encounter another panic during
that process, however, Rust will abort as usual for panic during
unwinding.
2018-03-25 23:26:20 +02:00
bluss 16aabf7c2c DOC: Fix typo in insert doc 2018-02-10 21:57:36 +01:00
bluss c1b72500cd REFAC Use clone_from_slice, extend in ArrayVec::clone_from
This is just a cleanup of the code, with less repetition.
2018-02-06 19:29:15 +01:00
bluss 2eeed4bae5 Merge pull request #90 from jeehoonkang/rust-1.12.1
Support Rust 1.13.0
2018-01-17 20:35:36 +01:00
bluss a903e1a770 FIX: Fix future compat warning with pointer casts
```
warning: the type of this value must be known in this context
   --> src/lib.rs:312:32
    |
312 |                 ptr::copy(p, p.offset(1), len - index);
    |                                ^^^^^^
    |
    = note: #[warn(tyvar_behind_raw_pointer)] on by default
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #46906 <https://github.com/rust-lang/rust/issues/46906>
```
2018-01-17 20:25:47 +01:00
Jeehoon Kang 3df64ccd50 Support Rust 1.13.0 2018-01-16 15:04:45 +09:00
bluss ef133ef960 FIX: Use drop_in_place in IntoIter's drop. 2017-12-03 21:57:38 +01:00
bluss a2e3fcea3f DOC: Minor fixes in docs, for ' → ’ 2017-10-27 22:54:46 +02:00
bluss 456aeaf557 FEAT: Remove odds dependency in arrayvec
Copy the encode_utf8 function from odds. std encode_utf8 requires Rust
1.15 and has a different signature, this one seems to fit us better.
2017-10-27 22:31:49 +02:00
bluss 895d450366 DOC: Promise debug assertions for unsafe methods
Instead of being vague about it, we can promise it.

We continue to be a bit vague in ArrayString::set_len.  I don't see how
to add a char boundary check in ArrayString::set_len unfortunately.

It's a tricky issue, checking char boundaries requires reading the
memory of the string, and we don't even know if the user of set_len has
initialized that area of memory yet (but they hopefully did).
2017-10-26 19:27:47 +02:00
Niklas Fiekas 5257cbd2b4 Add ArrayVec::truncate() 2017-10-18 18:14:07 +02:00
bluss ace20a9f43 DOC: Add docs for default values 2017-10-16 22:45:27 +02:00
bluss ac64b5b661 BUG: Fix "unused unsafe block" warning
This warning was only visible on stable, not nightly, which seems like
a bug.
2017-10-08 18:15:05 +02:00
bluss 793ad30be9 FEAT: Improve .extend() performance
We have to use the "SetLenOnDrop" pattern (see stdlib Vec) here.

Keep the length in a separate variable, write it back on scope exit. To
help the compiler with alias analysis and stuff.  We update the length
to handle panic in the iteration of the user's iterator, without
dropping any elements on the floor.

Note: This code was tested without the scope guard using the new option
-Zmutable-noalias, which had no effect here.

benchmark:

```
 name                  before.txt ns/iter  after.txt ns/iter  diff ns/iter   diff %
 extend_with_constant  280 (1828 MB/s)     74 (6918 MB/s)             -206  -73.57%
 extend_with_range     1,285 (398 MB/s)    979 (522 MB/s)             -306  -23.81%
 extend_with_slice     29 (17655 MB/s)     14 (36571 MB/s)             -15  -51.72%
```
2017-10-08 17:44:06 +02:00
bluss 9825e58061 FEAT: Add CapacityError::new 2017-09-24 18:07:12 +02:00
bluss f33c4e44dd DOC: Mention serde-1 feature 2017-09-11 19:43:54 +02:00
bluss cea481f494 0.4.0 2017-08-08 21:07:02 +02:00
bluss 878fef8d8a MAINT: Require Rust 1.14 2017-08-06 21:07:51 +02:00
bluss b2b377117a DOC: Update doc for and disclaimers for crate features 2017-08-06 18:32:08 +02:00
bluss 6ea8e8c0bf DOC: Update root crate url 2017-08-06 18:32:08 +02:00
bluss 696459db27 DOC: Fix typo in doc comment 2017-08-06 00:37:33 +02:00
bluss 689e55b61d DOC: Use ArrayVec in doc for drain 2017-08-05 18:29:28 +02:00
bluss 4c90dc782d DOC: Copyedit the docs a bit 2017-08-05 18:22:21 +02:00
bluss 313ebe8335 FEAT: Rename .remove_opt() to .pop_at() 2017-08-05 18:22:06 +02:00
bluss 27b8a0cb0c BUG: Make error module private again 2017-08-05 18:06:56 +02:00