| extern crate arrayvec; | ||
| #[macro_use] extern crate bencher; | ||
| use arrayvec::ArrayVec; | ||
| use bencher::Bencher; | ||
| fn extend_with_constant(b: &mut Bencher) { | ||
| let mut v = ArrayVec::<[u8; 512]>::new(); | ||
| let cap = v.capacity(); | ||
| b.iter(|| { | ||
| v.clear(); | ||
| v.extend((0..cap).map(|_| 1)); | ||
| v[0] | ||
| }); | ||
| b.bytes = v.capacity() as u64; | ||
| } | ||
| fn extend_with_range(b: &mut Bencher) { | ||
| let mut v = ArrayVec::<[u8; 512]>::new(); | ||
| let cap = v.capacity(); | ||
| b.iter(|| { | ||
| v.clear(); | ||
| v.extend((0..cap).map(|x| x as _)); | ||
| v[0] | ||
| }); | ||
| b.bytes = v.capacity() as u64; | ||
| } | ||
| fn extend_with_slice(b: &mut Bencher) { | ||
| let mut v = ArrayVec::<[u8; 512]>::new(); | ||
| let data = [1; 512]; | ||
| b.iter(|| { | ||
| v.clear(); | ||
| v.extend(data.iter().cloned()); | ||
| v[0] | ||
| }); | ||
| b.bytes = v.capacity() as u64; | ||
| } | ||
| benchmark_group!(benches, extend_with_constant, extend_with_range, extend_with_slice); | ||
| benchmark_main!(benches); |
+1
-0
@@ -11,2 +11,3 @@ language: rust | ||
| - NODEFAULT=1 | ||
| - NODROP_FEATURES='use_needs_drop' | ||
| - rust: beta | ||
@@ -13,0 +14,0 @@ - rust: nightly |
+16
-9
@@ -15,3 +15,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| name = "arrayvec" | ||
| version = "0.4.2" | ||
| version = "0.4.3" | ||
| authors = ["bluss"] | ||
@@ -29,2 +29,6 @@ description = "A vector with fixed capacity, backed by an array (it can be stored on the stack too). Implements fixed capacity ArrayVec and ArrayString." | ||
| no-dev-version = true | ||
| [[bench]] | ||
| name = "extend" | ||
| harness = false | ||
| [dependencies.odds] | ||
@@ -34,6 +38,2 @@ version = "0.2.23" | ||
| [dependencies.nodrop] | ||
| version = "0.1.8" | ||
| default-features = false | ||
| [dependencies.serde] | ||
@@ -43,12 +43,19 @@ version = "1.0" | ||
| default-features = false | ||
| [dev-dependencies.serde_test] | ||
| version = "1.0" | ||
| [dependencies.nodrop] | ||
| version = "0.1.8" | ||
| default-features = false | ||
| [dev-dependencies.matches] | ||
| version = "0.1" | ||
| [dev-dependencies.serde_test] | ||
| version = "1.0" | ||
| [dev-dependencies.bencher] | ||
| version = "0.1.4" | ||
| [features] | ||
| std = ["odds/std", "nodrop/std"] | ||
| std = [] | ||
| serde-1 = ["serde"] | ||
| default = ["std"] | ||
| serde-1 = ["serde"] | ||
| use_union = [] |
+7
-1
@@ -9,3 +9,3 @@ | ||
| __ https://bluss.github.io/arrayvec | ||
| __ https://docs.rs/arrayvec | ||
@@ -26,2 +26,8 @@ |build_status|_ |crates|_ |crates2|_ | ||
| - 0.4.3 | ||
| - Improve performance for ``ArrayVec::extend`` with a lower level | ||
| implementation (#74) | ||
| - Small cleanup in dependencies (use no std for crates where we don't need more) | ||
| - 0.4.2 | ||
@@ -28,0 +34,0 @@ |
+33
-3
@@ -808,5 +808,20 @@ //! **arrayvec** provides the types `ArrayVec` and `ArrayString`: | ||
| struct ScopeExitGuard<T, Data, F> | ||
| where F: FnMut(&Data, &mut T) | ||
| { | ||
| value: T, | ||
| data: Data, | ||
| f: F, | ||
| } | ||
| impl<T, Data, F> Drop for ScopeExitGuard<T, Data, F> | ||
| where F: FnMut(&Data, &mut T) | ||
| { | ||
| fn drop(&mut self) { | ||
| (self.f)(&self.data, &mut self.value) | ||
| } | ||
| } | ||
| /// Extend the `ArrayVec` with an iterator. | ||
@@ -819,5 +834,20 @@ /// | ||
| let take = self.capacity() - self.len(); | ||
| for elt in iter.into_iter().take(take) { | ||
| unsafe { | ||
| self.push_unchecked(elt); | ||
| unsafe { | ||
| let len = self.len(); | ||
| let mut ptr = self.as_mut_ptr().offset(len as isize); | ||
| // 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. | ||
| let mut guard = ScopeExitGuard { | ||
| value: self, | ||
| data: len, | ||
| f: |&len, self_| { | ||
| self_.set_len(len) | ||
| } | ||
| }; | ||
| for elt in iter.into_iter().take(take) { | ||
| ptr::write(ptr, elt); | ||
| ptr = ptr.offset(1); | ||
| guard.data += 1; | ||
| } | ||
@@ -824,0 +854,0 @@ } |
-35
| DOCCRATES = arrayvec nodrop nodrop_union odds | ||
| # deps to delete the generated docs | ||
| RMDOCS = | ||
| FEATURES = "odds/unstable" | ||
| VERSIONS = $(patsubst %,target/VERS/%,$(DOCCRATES)) | ||
| docs: mkdocs subst $(RMDOCS) | ||
| # https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html | ||
| $(VERSIONS): Cargo.toml | ||
| mkdir -p $(@D) | ||
| cargo pkgid $(@F) | sed -e "s/.*#\(\|.*:\)//" > "$@" | ||
| $(DOCCRATES): %: target/VERS/% | ||
| # Put in the crate version into the docs | ||
| find ./doc/$@ -name "*.html" -exec sed -i -e "s/<title>\(.*\) - Rust/<title>$@ $(shell cat $<) - \1 - Rust/g" {} \; | ||
| subst: $(DOCCRATES) | ||
| mkdocs: Cargo.toml | ||
| cargo doc --features=$(FEATURES) | ||
| cargo doc --features=use_union -p nodrop-union | ||
| rm -rf ./doc | ||
| cp -r ./target/doc ./doc | ||
| -cat ./custom.css >> doc/main.css | ||
| $(RMDOCS): mkdocs | ||
| rm -r ./doc/$@ | ||
| sed -i "/searchIndex\['$@'\]/d" doc/search-index.js | ||
| .PHONY: docs mkdocs subst $(DOCCRATES) $(RMDOCS) |
Sorry, the diff of this file is not supported yet