更新libclamav库1.0.0版本
This commit is contained in:
1
clamav/libclamav_rust/.cargo/vendor/smallvec/.cargo-checksum.json
vendored
Normal file
1
clamav/libclamav_rust/.cargo/vendor/smallvec/.cargo-checksum.json
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"files":{"Cargo.toml":"e8b7e22c87fa34e053c12b3751ec0c7b25b37bd1285959710321a7a00861f392","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"0b28172679e0009b655da42797c03fd163a3379d5cfa67ba1f1655e974a2a1a9","README.md":"a01127c37308457e8d396b176fb790846be0978c173be3f13260b62efcef011b","benches/bench.rs":"e2a235d68be20996014c00468b369887d2041ce95486625de3cef35b8f2e4acd","debug_metadata/README.md":"dc8fbf896055359a94f7bfdfae7604e0bcfc8b10998a218d484d9fffdf83637c","debug_metadata/smallvec.natvis":"68aed2322bdc13ed6fa2021dc9625346174d73590929acbc2f95c98785c8dee4","scripts/run_miri.sh":"74a9f9adc43f986e81977b03846f7dd00122a0150bd8ec3fe4842a1a787e0f07","src/arbitrary.rs":"22e55cfbf60374945b30e6d0855129eff67cd8b878cef6fa997e1f4be67b9e3d","src/lib.rs":"35c60a9d9240853e9f6f84b7a44ff6a3197a87ab404f5ab1cd8ebeeeb72e54da","src/specialization.rs":"46433586203399251cba496d67b88d34e1be3c2b591986b77463513da1c66471","src/tests.rs":"2bcf69dc0597e4e8a59a92566a3dd5c82ec3a1ea563aa006ea0f4a2722cb2d17","tests/debugger_visualizer.rs":"87480900add8579e1285741d5a0041063b6d888328e11854ab2cdc2960d7ddb1","tests/macro.rs":"22ad4f6f104a599fdcba19cad8834105b8656b212fb6c7573a427d447f5db14f"},"package":"a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"}
|
||||
69
clamav/libclamav_rust/.cargo/vendor/smallvec/Cargo.toml
vendored
Normal file
69
clamav/libclamav_rust/.cargo/vendor/smallvec/Cargo.toml
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
edition = "2018"
|
||||
name = "smallvec"
|
||||
version = "1.10.0"
|
||||
authors = ["The Servo Project Developers"]
|
||||
description = "'Small vector' optimization: store up to a small number of items on the stack"
|
||||
documentation = "https://docs.rs/smallvec/"
|
||||
readme = "README.md"
|
||||
keywords = [
|
||||
"small",
|
||||
"vec",
|
||||
"vector",
|
||||
"stack",
|
||||
"no_std",
|
||||
]
|
||||
categories = ["data-structures"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/servo/rust-smallvec"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = [
|
||||
"--cfg",
|
||||
"docsrs",
|
||||
]
|
||||
|
||||
[[test]]
|
||||
name = "debugger_visualizer"
|
||||
path = "tests/debugger_visualizer.rs"
|
||||
test = false
|
||||
required-features = ["debugger_visualizer"]
|
||||
|
||||
[dependencies.arbitrary]
|
||||
version = "1"
|
||||
optional = true
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dev-dependencies.bincode]
|
||||
version = "1.0.1"
|
||||
|
||||
[dev-dependencies.debugger_test]
|
||||
version = "0.1.0"
|
||||
|
||||
[dev-dependencies.debugger_test_parser]
|
||||
version = "0.1.0"
|
||||
|
||||
[features]
|
||||
const_generics = []
|
||||
const_new = ["const_generics"]
|
||||
debugger_visualizer = []
|
||||
may_dangle = []
|
||||
specialization = []
|
||||
union = []
|
||||
write = []
|
||||
201
clamav/libclamav_rust/.cargo/vendor/smallvec/LICENSE-APACHE
vendored
Normal file
201
clamav/libclamav_rust/.cargo/vendor/smallvec/LICENSE-APACHE
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
25
clamav/libclamav_rust/.cargo/vendor/smallvec/LICENSE-MIT
vendored
Normal file
25
clamav/libclamav_rust/.cargo/vendor/smallvec/LICENSE-MIT
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
Copyright (c) 2018 The Servo Project Developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
26
clamav/libclamav_rust/.cargo/vendor/smallvec/README.md
vendored
Normal file
26
clamav/libclamav_rust/.cargo/vendor/smallvec/README.md
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
rust-smallvec
|
||||
=============
|
||||
|
||||
[Documentation](https://docs.rs/smallvec/)
|
||||
|
||||
[Release notes](https://github.com/servo/rust-smallvec/releases)
|
||||
|
||||
"Small vector" optimization for Rust: store up to a small number of items on the stack
|
||||
|
||||
## Example
|
||||
|
||||
```rust
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
|
||||
// This SmallVec can hold up to 4 items on the stack:
|
||||
let mut v: SmallVec<[i32; 4]> = smallvec![1, 2, 3, 4];
|
||||
|
||||
// It will automatically move its contents to the heap if
|
||||
// contains more than four items:
|
||||
v.push(5);
|
||||
|
||||
// SmallVec points to a slice, so you can use normal slice
|
||||
// indexing and other methods to access its contents:
|
||||
v[0] = v[1] + v[2];
|
||||
v.sort();
|
||||
```
|
||||
314
clamav/libclamav_rust/.cargo/vendor/smallvec/benches/bench.rs
vendored
Normal file
314
clamav/libclamav_rust/.cargo/vendor/smallvec/benches/bench.rs
vendored
Normal file
@@ -0,0 +1,314 @@
|
||||
#![feature(test)]
|
||||
#![allow(deprecated)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate smallvec;
|
||||
extern crate test;
|
||||
|
||||
use self::test::Bencher;
|
||||
use smallvec::{ExtendFromSlice, SmallVec};
|
||||
|
||||
const VEC_SIZE: usize = 16;
|
||||
const SPILLED_SIZE: usize = 100;
|
||||
|
||||
trait Vector<T>: for<'a> From<&'a [T]> + Extend<T> + ExtendFromSlice<T> {
|
||||
fn new() -> Self;
|
||||
fn push(&mut self, val: T);
|
||||
fn pop(&mut self) -> Option<T>;
|
||||
fn remove(&mut self, p: usize) -> T;
|
||||
fn insert(&mut self, n: usize, val: T);
|
||||
fn from_elem(val: T, n: usize) -> Self;
|
||||
fn from_elems(val: &[T]) -> Self;
|
||||
}
|
||||
|
||||
impl<T: Copy> Vector<T> for Vec<T> {
|
||||
fn new() -> Self {
|
||||
Self::with_capacity(VEC_SIZE)
|
||||
}
|
||||
|
||||
fn push(&mut self, val: T) {
|
||||
self.push(val)
|
||||
}
|
||||
|
||||
fn pop(&mut self) -> Option<T> {
|
||||
self.pop()
|
||||
}
|
||||
|
||||
fn remove(&mut self, p: usize) -> T {
|
||||
self.remove(p)
|
||||
}
|
||||
|
||||
fn insert(&mut self, n: usize, val: T) {
|
||||
self.insert(n, val)
|
||||
}
|
||||
|
||||
fn from_elem(val: T, n: usize) -> Self {
|
||||
vec![val; n]
|
||||
}
|
||||
|
||||
fn from_elems(val: &[T]) -> Self {
|
||||
val.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy> Vector<T> for SmallVec<[T; VEC_SIZE]> {
|
||||
fn new() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
|
||||
fn push(&mut self, val: T) {
|
||||
self.push(val)
|
||||
}
|
||||
|
||||
fn pop(&mut self) -> Option<T> {
|
||||
self.pop()
|
||||
}
|
||||
|
||||
fn remove(&mut self, p: usize) -> T {
|
||||
self.remove(p)
|
||||
}
|
||||
|
||||
fn insert(&mut self, n: usize, val: T) {
|
||||
self.insert(n, val)
|
||||
}
|
||||
|
||||
fn from_elem(val: T, n: usize) -> Self {
|
||||
smallvec![val; n]
|
||||
}
|
||||
|
||||
fn from_elems(val: &[T]) -> Self {
|
||||
SmallVec::from_slice(val)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! make_benches {
|
||||
($typ:ty { $($b_name:ident => $g_name:ident($($args:expr),*),)* }) => {
|
||||
$(
|
||||
#[bench]
|
||||
fn $b_name(b: &mut Bencher) {
|
||||
$g_name::<$typ>($($args,)* b)
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
make_benches! {
|
||||
SmallVec<[u64; VEC_SIZE]> {
|
||||
bench_push => gen_push(SPILLED_SIZE as _),
|
||||
bench_push_small => gen_push(VEC_SIZE as _),
|
||||
bench_insert_push => gen_insert_push(SPILLED_SIZE as _),
|
||||
bench_insert_push_small => gen_insert_push(VEC_SIZE as _),
|
||||
bench_insert => gen_insert(SPILLED_SIZE as _),
|
||||
bench_insert_small => gen_insert(VEC_SIZE as _),
|
||||
bench_remove => gen_remove(SPILLED_SIZE as _),
|
||||
bench_remove_small => gen_remove(VEC_SIZE as _),
|
||||
bench_extend => gen_extend(SPILLED_SIZE as _),
|
||||
bench_extend_small => gen_extend(VEC_SIZE as _),
|
||||
bench_from_iter => gen_from_iter(SPILLED_SIZE as _),
|
||||
bench_from_iter_small => gen_from_iter(VEC_SIZE as _),
|
||||
bench_from_slice => gen_from_slice(SPILLED_SIZE as _),
|
||||
bench_from_slice_small => gen_from_slice(VEC_SIZE as _),
|
||||
bench_extend_from_slice => gen_extend_from_slice(SPILLED_SIZE as _),
|
||||
bench_extend_from_slice_small => gen_extend_from_slice(VEC_SIZE as _),
|
||||
bench_macro_from_elem => gen_from_elem(SPILLED_SIZE as _),
|
||||
bench_macro_from_elem_small => gen_from_elem(VEC_SIZE as _),
|
||||
bench_pushpop => gen_pushpop(),
|
||||
}
|
||||
}
|
||||
|
||||
make_benches! {
|
||||
Vec<u64> {
|
||||
bench_push_vec => gen_push(SPILLED_SIZE as _),
|
||||
bench_push_vec_small => gen_push(VEC_SIZE as _),
|
||||
bench_insert_push_vec => gen_insert_push(SPILLED_SIZE as _),
|
||||
bench_insert_push_vec_small => gen_insert_push(VEC_SIZE as _),
|
||||
bench_insert_vec => gen_insert(SPILLED_SIZE as _),
|
||||
bench_insert_vec_small => gen_insert(VEC_SIZE as _),
|
||||
bench_remove_vec => gen_remove(SPILLED_SIZE as _),
|
||||
bench_remove_vec_small => gen_remove(VEC_SIZE as _),
|
||||
bench_extend_vec => gen_extend(SPILLED_SIZE as _),
|
||||
bench_extend_vec_small => gen_extend(VEC_SIZE as _),
|
||||
bench_from_iter_vec => gen_from_iter(SPILLED_SIZE as _),
|
||||
bench_from_iter_vec_small => gen_from_iter(VEC_SIZE as _),
|
||||
bench_from_slice_vec => gen_from_slice(SPILLED_SIZE as _),
|
||||
bench_from_slice_vec_small => gen_from_slice(VEC_SIZE as _),
|
||||
bench_extend_from_slice_vec => gen_extend_from_slice(SPILLED_SIZE as _),
|
||||
bench_extend_from_slice_vec_small => gen_extend_from_slice(VEC_SIZE as _),
|
||||
bench_macro_from_elem_vec => gen_from_elem(SPILLED_SIZE as _),
|
||||
bench_macro_from_elem_vec_small => gen_from_elem(VEC_SIZE as _),
|
||||
bench_pushpop_vec => gen_pushpop(),
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_push<V: Vector<u64>>(n: u64, b: &mut Bencher) {
|
||||
#[inline(never)]
|
||||
fn push_noinline<V: Vector<u64>>(vec: &mut V, x: u64) {
|
||||
vec.push(x);
|
||||
}
|
||||
|
||||
b.iter(|| {
|
||||
let mut vec = V::new();
|
||||
for x in 0..n {
|
||||
push_noinline(&mut vec, x);
|
||||
}
|
||||
vec
|
||||
});
|
||||
}
|
||||
|
||||
fn gen_insert_push<V: Vector<u64>>(n: u64, b: &mut Bencher) {
|
||||
#[inline(never)]
|
||||
fn insert_push_noinline<V: Vector<u64>>(vec: &mut V, x: u64) {
|
||||
vec.insert(x as usize, x);
|
||||
}
|
||||
|
||||
b.iter(|| {
|
||||
let mut vec = V::new();
|
||||
for x in 0..n {
|
||||
insert_push_noinline(&mut vec, x);
|
||||
}
|
||||
vec
|
||||
});
|
||||
}
|
||||
|
||||
fn gen_insert<V: Vector<u64>>(n: u64, b: &mut Bencher) {
|
||||
#[inline(never)]
|
||||
fn insert_noinline<V: Vector<u64>>(vec: &mut V, p: usize, x: u64) {
|
||||
vec.insert(p, x)
|
||||
}
|
||||
|
||||
b.iter(|| {
|
||||
let mut vec = V::new();
|
||||
// Always insert at position 0 so that we are subject to shifts of
|
||||
// many different lengths.
|
||||
vec.push(0);
|
||||
for x in 0..n {
|
||||
insert_noinline(&mut vec, 0, x);
|
||||
}
|
||||
vec
|
||||
});
|
||||
}
|
||||
|
||||
fn gen_remove<V: Vector<u64>>(n: usize, b: &mut Bencher) {
|
||||
#[inline(never)]
|
||||
fn remove_noinline<V: Vector<u64>>(vec: &mut V, p: usize) -> u64 {
|
||||
vec.remove(p)
|
||||
}
|
||||
|
||||
b.iter(|| {
|
||||
let mut vec = V::from_elem(0, n as _);
|
||||
|
||||
for _ in 0..n {
|
||||
remove_noinline(&mut vec, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn gen_extend<V: Vector<u64>>(n: u64, b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let mut vec = V::new();
|
||||
vec.extend(0..n);
|
||||
vec
|
||||
});
|
||||
}
|
||||
|
||||
fn gen_from_iter<V: Vector<u64>>(n: u64, b: &mut Bencher) {
|
||||
let v: Vec<u64> = (0..n).collect();
|
||||
b.iter(|| {
|
||||
let vec = V::from(&v);
|
||||
vec
|
||||
});
|
||||
}
|
||||
|
||||
fn gen_from_slice<V: Vector<u64>>(n: u64, b: &mut Bencher) {
|
||||
let v: Vec<u64> = (0..n).collect();
|
||||
b.iter(|| {
|
||||
let vec = V::from_elems(&v);
|
||||
vec
|
||||
});
|
||||
}
|
||||
|
||||
fn gen_extend_from_slice<V: Vector<u64>>(n: u64, b: &mut Bencher) {
|
||||
let v: Vec<u64> = (0..n).collect();
|
||||
b.iter(|| {
|
||||
let mut vec = V::new();
|
||||
vec.extend_from_slice(&v);
|
||||
vec
|
||||
});
|
||||
}
|
||||
|
||||
fn gen_pushpop<V: Vector<u64>>(b: &mut Bencher) {
|
||||
#[inline(never)]
|
||||
fn pushpop_noinline<V: Vector<u64>>(vec: &mut V, x: u64) -> Option<u64> {
|
||||
vec.push(x);
|
||||
vec.pop()
|
||||
}
|
||||
|
||||
b.iter(|| {
|
||||
let mut vec = V::new();
|
||||
for x in 0..SPILLED_SIZE as _ {
|
||||
pushpop_noinline(&mut vec, x);
|
||||
}
|
||||
vec
|
||||
});
|
||||
}
|
||||
|
||||
fn gen_from_elem<V: Vector<u64>>(n: usize, b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let vec = V::from_elem(42, n);
|
||||
vec
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_insert_many(b: &mut Bencher) {
|
||||
#[inline(never)]
|
||||
fn insert_many_noinline<I: IntoIterator<Item = u64>>(
|
||||
vec: &mut SmallVec<[u64; VEC_SIZE]>,
|
||||
index: usize,
|
||||
iterable: I,
|
||||
) {
|
||||
vec.insert_many(index, iterable)
|
||||
}
|
||||
|
||||
b.iter(|| {
|
||||
let mut vec = SmallVec::<[u64; VEC_SIZE]>::new();
|
||||
insert_many_noinline(&mut vec, 0, 0..SPILLED_SIZE as _);
|
||||
insert_many_noinline(&mut vec, 0, 0..SPILLED_SIZE as _);
|
||||
vec
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_insert_from_slice(b: &mut Bencher) {
|
||||
let v: Vec<u64> = (0..SPILLED_SIZE as _).collect();
|
||||
b.iter(|| {
|
||||
let mut vec = SmallVec::<[u64; VEC_SIZE]>::new();
|
||||
vec.insert_from_slice(0, &v);
|
||||
vec.insert_from_slice(0, &v);
|
||||
vec
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_macro_from_list(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let vec: SmallVec<[u64; 16]> = smallvec![
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 24, 32, 36, 0x40, 0x80,
|
||||
0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, 0x10000, 0x20000, 0x40000,
|
||||
0x80000, 0x100000,
|
||||
];
|
||||
vec
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_macro_from_list_vec(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let vec: Vec<u64> = vec![
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 24, 32, 36, 0x40, 0x80,
|
||||
0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, 0x10000, 0x20000, 0x40000,
|
||||
0x80000, 0x100000,
|
||||
];
|
||||
vec
|
||||
});
|
||||
}
|
||||
111
clamav/libclamav_rust/.cargo/vendor/smallvec/debug_metadata/README.md
vendored
Normal file
111
clamav/libclamav_rust/.cargo/vendor/smallvec/debug_metadata/README.md
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
## Debugger Visualizers
|
||||
|
||||
Many languages and debuggers enable developers to control how a type is
|
||||
displayed in a debugger. These are called "debugger visualizations" or "debugger
|
||||
views".
|
||||
|
||||
The Windows debuggers (WinDbg\CDB) support defining custom debugger visualizations using
|
||||
the `Natvis` framework. To use Natvis, developers write XML documents using the natvis
|
||||
schema that describe how debugger types should be displayed with the `.natvis` extension.
|
||||
(See: https://docs.microsoft.com/en-us/visualstudio/debugger/create-custom-views-of-native-objects?view=vs-2019)
|
||||
The Natvis files provide patterns which match type names a description of how to display
|
||||
those types.
|
||||
|
||||
The Natvis schema can be found either online (See: https://code.visualstudio.com/docs/cpp/natvis#_schema)
|
||||
or locally at `<VS Installation Folder>\Xml\Schemas\1033\natvis.xsd`.
|
||||
|
||||
The GNU debugger (GDB) supports defining custom debugger views using Pretty Printers.
|
||||
Pretty printers are written as python scripts that describe how a type should be displayed
|
||||
when loaded up in GDB/LLDB. (See: https://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing.html#Pretty-Printing)
|
||||
The pretty printers provide patterns, which match type names, and for matching
|
||||
types, descibe how to display those types. (For writing a pretty printer, see: https://sourceware.org/gdb/onlinedocs/gdb/Writing-a-Pretty_002dPrinter.html#Writing-a-Pretty_002dPrinter).
|
||||
|
||||
### Embedding Visualizers
|
||||
|
||||
Through the use of the currently unstable `#[debugger_visualizer]` attribute, the `smallvec`
|
||||
crate can embed debugger visualizers into the crate metadata.
|
||||
|
||||
Currently the two types of visualizers supported are Natvis and Pretty printers.
|
||||
|
||||
For Natvis files, when linking an executable with a crate that includes Natvis files,
|
||||
the MSVC linker will embed the contents of all Natvis files into the generated `PDB`.
|
||||
|
||||
For pretty printers, the compiler will encode the contents of the pretty printer
|
||||
in the `.debug_gdb_scripts` section of the `ELF` generated.
|
||||
|
||||
### Testing Visualizers
|
||||
|
||||
The `smallvec` crate supports testing debugger visualizers defined for this crate. The entry point for
|
||||
these tests are `tests/debugger_visualizer.rs`. These tests are defined using the `debugger_test` and
|
||||
`debugger_test_parser` crates. The `debugger_test` crate is a proc macro crate which defines a
|
||||
single proc macro attribute, `#[debugger_test]`. For more detailed information about this crate,
|
||||
see https://crates.io/crates/debugger_test. The CI pipeline for the `smallvec` crate has been updated
|
||||
to run the debugger visualizer tests to ensure debugger visualizers do not become broken/stale.
|
||||
|
||||
The `#[debugger_test]` proc macro attribute may only be used on test functions and will run the
|
||||
function under the debugger specified by the `debugger` meta item.
|
||||
|
||||
This proc macro attribute has 3 required values:
|
||||
|
||||
1. The first required meta item, `debugger`, takes a string value which specifies the debugger to launch.
|
||||
2. The second required meta item, `commands`, takes a string of new line (`\n`) separated list of debugger
|
||||
commands to run.
|
||||
3. The third required meta item, `expected_statements`, takes a string of new line (`\n`) separated list of
|
||||
statements that must exist in the debugger output. Pattern matching through regular expressions is also
|
||||
supported by using the `pattern:` prefix for each expected statement.
|
||||
|
||||
#### Example:
|
||||
|
||||
```rust
|
||||
#[debugger_test(
|
||||
debugger = "cdb",
|
||||
commands = "command1\ncommand2\ncommand3",
|
||||
expected_statements = "statement1\nstatement2\nstatement3")]
|
||||
fn test() {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
Using a multiline string is also supported, with a single debugger command/expected statement per line:
|
||||
|
||||
```rust
|
||||
#[debugger_test(
|
||||
debugger = "cdb",
|
||||
commands = "
|
||||
command1
|
||||
command2
|
||||
command3",
|
||||
expected_statements = "
|
||||
statement1
|
||||
pattern:statement[0-9]+
|
||||
statement3")]
|
||||
fn test() {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
In the example above, the second expected statement uses pattern matching through a regular expression
|
||||
by using the `pattern:` prefix.
|
||||
|
||||
#### Testing Locally
|
||||
|
||||
Currently, only Natvis visualizations have been defined for the `smallvec` crate via `debug_metadata/smallvec.natvis`,
|
||||
which means the `tests/debugger_visualizer.rs` tests need to be run on Windows using the `*-pc-windows-msvc` targets.
|
||||
To run these tests locally, first ensure the debugging tools for Windows are installed or install them following
|
||||
the steps listed here, [Debugging Tools for Windows](https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/).
|
||||
Once the debugging tools have been installed, the tests can be run in the same manner as they are in the CI
|
||||
pipeline.
|
||||
|
||||
#### Note
|
||||
|
||||
When running the debugger visualizer tests, `tests/debugger_visualizer.rs`, they need to be run consecutively
|
||||
and not in parallel. This can be achieved by passing the flag `--test-threads=1` to rustc. This is due to
|
||||
how the debugger tests are run. Each test marked with the `#[debugger_test]` attribute launches a debugger
|
||||
and attaches it to the current test process. If tests are running in parallel, the test will try to attach
|
||||
a debugger to the current process which may already have a debugger attached causing the test to fail.
|
||||
|
||||
For example:
|
||||
|
||||
```
|
||||
cargo test --test debugger_visualizer --features debugger_visualizer -- --test-threads=1
|
||||
```
|
||||
35
clamav/libclamav_rust/.cargo/vendor/smallvec/debug_metadata/smallvec.natvis
vendored
Normal file
35
clamav/libclamav_rust/.cargo/vendor/smallvec/debug_metadata/smallvec.natvis
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||
<Type Name="smallvec::SmallVec<array$<*,*>>" Priority="Medium">
|
||||
<Intrinsic Name="is_inline" Expression="$T2 > capacity" />
|
||||
<Intrinsic Name="len" Expression="is_inline() ? capacity : data.variant1.value.__0.__1" />
|
||||
<Intrinsic Name="data_ptr" Expression="is_inline() ? data.variant0.value.__0.value.value : data.variant1.value.__0.__0" />
|
||||
|
||||
<DisplayString>{{ len={len()} }}</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="[capacity]">is_inline() ? $T2 : capacity</Item>
|
||||
<Item Name="[len]">len()</Item>
|
||||
|
||||
<ArrayItems>
|
||||
<Size>len()</Size>
|
||||
<ValuePointer>data_ptr()</ValuePointer>
|
||||
</ArrayItems>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<Type Name="smallvec::SmallVec<array$<*,*>>" Priority="MediumLow">
|
||||
<Intrinsic Name="is_inline" Expression="$T2 > capacity" />
|
||||
<Intrinsic Name="len" Expression="is_inline() ? capacity : data.heap.__1" />
|
||||
<Intrinsic Name="data_ptr" Expression="is_inline() ? data.inline.value.value.value : data.heap.__0" />
|
||||
|
||||
<DisplayString>{{ len={len()} }}</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="[capacity]">is_inline() ? $T2 : capacity</Item>
|
||||
<Item Name="[len]">len()</Item>
|
||||
|
||||
<ArrayItems>
|
||||
<Size>len()</Size>
|
||||
<ValuePointer>data_ptr()</ValuePointer>
|
||||
</ArrayItems>
|
||||
</Expand>
|
||||
</Type>
|
||||
</AutoVisualizer>
|
||||
24
clamav/libclamav_rust/.cargo/vendor/smallvec/scripts/run_miri.sh
vendored
Normal file
24
clamav/libclamav_rust/.cargo/vendor/smallvec/scripts/run_miri.sh
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
# Clean out our target dir, which may have artifacts compiled by a version of
|
||||
# rust different from the one we're about to download.
|
||||
cargo clean
|
||||
|
||||
# Install and run the latest version of nightly where miri built successfully.
|
||||
# Taken from: https://github.com/rust-lang/miri#running-miri-on-ci
|
||||
|
||||
MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)
|
||||
echo "Installing latest nightly with Miri: $MIRI_NIGHTLY"
|
||||
rustup override unset
|
||||
rustup default "$MIRI_NIGHTLY"
|
||||
|
||||
rustup component add miri
|
||||
cargo miri setup
|
||||
|
||||
cargo miri test --verbose
|
||||
cargo miri test --verbose --features union
|
||||
cargo miri test --verbose --all-features
|
||||
|
||||
rustup override set nightly
|
||||
19
clamav/libclamav_rust/.cargo/vendor/smallvec/src/arbitrary.rs
vendored
Normal file
19
clamav/libclamav_rust/.cargo/vendor/smallvec/src/arbitrary.rs
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
use crate::{Array, SmallVec};
|
||||
use arbitrary::{Arbitrary, Unstructured};
|
||||
|
||||
impl<'a, A: Array> Arbitrary<'a> for SmallVec<A>
|
||||
where
|
||||
<A as Array>::Item: Arbitrary<'a>,
|
||||
{
|
||||
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
|
||||
u.arbitrary_iter()?.collect()
|
||||
}
|
||||
|
||||
fn arbitrary_take_rest(u: Unstructured<'a>) -> arbitrary::Result<Self> {
|
||||
u.arbitrary_take_rest_iter()?.collect()
|
||||
}
|
||||
|
||||
fn size_hint(depth: usize) -> (usize, Option<usize>) {
|
||||
arbitrary::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
|
||||
}
|
||||
}
|
||||
2132
clamav/libclamav_rust/.cargo/vendor/smallvec/src/lib.rs
vendored
Normal file
2132
clamav/libclamav_rust/.cargo/vendor/smallvec/src/lib.rs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
19
clamav/libclamav_rust/.cargo/vendor/smallvec/src/specialization.rs
vendored
Normal file
19
clamav/libclamav_rust/.cargo/vendor/smallvec/src/specialization.rs
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! Implementations that require `default fn`.
|
||||
|
||||
use super::{Array, SmallVec, SpecFrom};
|
||||
|
||||
impl<'a, A: Array> SpecFrom<A, &'a [A::Item]> for SmallVec<A>
|
||||
where
|
||||
A::Item: Clone,
|
||||
{
|
||||
#[inline]
|
||||
default fn spec_from(slice: &'a [A::Item]) -> SmallVec<A> {
|
||||
slice.into_iter().cloned().collect()
|
||||
}
|
||||
}
|
||||
985
clamav/libclamav_rust/.cargo/vendor/smallvec/src/tests.rs
vendored
Normal file
985
clamav/libclamav_rust/.cargo/vendor/smallvec/src/tests.rs
vendored
Normal file
@@ -0,0 +1,985 @@
|
||||
use crate::{smallvec, SmallVec};
|
||||
|
||||
use std::iter::FromIterator;
|
||||
|
||||
use alloc::borrow::ToOwned;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::rc::Rc;
|
||||
use alloc::{vec, vec::Vec};
|
||||
|
||||
#[test]
|
||||
pub fn test_zero() {
|
||||
let mut v = SmallVec::<[_; 0]>::new();
|
||||
assert!(!v.spilled());
|
||||
v.push(0usize);
|
||||
assert!(v.spilled());
|
||||
assert_eq!(&*v, &[0]);
|
||||
}
|
||||
|
||||
// We heap allocate all these strings so that double frees will show up under valgrind.
|
||||
|
||||
#[test]
|
||||
pub fn test_inline() {
|
||||
let mut v = SmallVec::<[_; 16]>::new();
|
||||
v.push("hello".to_owned());
|
||||
v.push("there".to_owned());
|
||||
assert_eq!(&*v, &["hello".to_owned(), "there".to_owned(),][..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_spill() {
|
||||
let mut v = SmallVec::<[_; 2]>::new();
|
||||
v.push("hello".to_owned());
|
||||
assert_eq!(v[0], "hello");
|
||||
v.push("there".to_owned());
|
||||
v.push("burma".to_owned());
|
||||
assert_eq!(v[0], "hello");
|
||||
v.push("shave".to_owned());
|
||||
assert_eq!(
|
||||
&*v,
|
||||
&[
|
||||
"hello".to_owned(),
|
||||
"there".to_owned(),
|
||||
"burma".to_owned(),
|
||||
"shave".to_owned(),
|
||||
][..]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_double_spill() {
|
||||
let mut v = SmallVec::<[_; 2]>::new();
|
||||
v.push("hello".to_owned());
|
||||
v.push("there".to_owned());
|
||||
v.push("burma".to_owned());
|
||||
v.push("shave".to_owned());
|
||||
v.push("hello".to_owned());
|
||||
v.push("there".to_owned());
|
||||
v.push("burma".to_owned());
|
||||
v.push("shave".to_owned());
|
||||
assert_eq!(
|
||||
&*v,
|
||||
&[
|
||||
"hello".to_owned(),
|
||||
"there".to_owned(),
|
||||
"burma".to_owned(),
|
||||
"shave".to_owned(),
|
||||
"hello".to_owned(),
|
||||
"there".to_owned(),
|
||||
"burma".to_owned(),
|
||||
"shave".to_owned(),
|
||||
][..]
|
||||
);
|
||||
}
|
||||
|
||||
/// https://github.com/servo/rust-smallvec/issues/4
|
||||
#[test]
|
||||
fn issue_4() {
|
||||
SmallVec::<[Box<u32>; 2]>::new();
|
||||
}
|
||||
|
||||
/// https://github.com/servo/rust-smallvec/issues/5
|
||||
#[test]
|
||||
fn issue_5() {
|
||||
assert!(Some(SmallVec::<[&u32; 2]>::new()).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_capacity() {
|
||||
let v: SmallVec<[u8; 3]> = SmallVec::with_capacity(1);
|
||||
assert!(v.is_empty());
|
||||
assert!(!v.spilled());
|
||||
assert_eq!(v.capacity(), 3);
|
||||
|
||||
let v: SmallVec<[u8; 3]> = SmallVec::with_capacity(10);
|
||||
assert!(v.is_empty());
|
||||
assert!(v.spilled());
|
||||
assert_eq!(v.capacity(), 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drain() {
|
||||
let mut v: SmallVec<[u8; 2]> = SmallVec::new();
|
||||
v.push(3);
|
||||
assert_eq!(v.drain(..).collect::<Vec<_>>(), &[3]);
|
||||
|
||||
// spilling the vec
|
||||
v.push(3);
|
||||
v.push(4);
|
||||
v.push(5);
|
||||
let old_capacity = v.capacity();
|
||||
assert_eq!(v.drain(1..).collect::<Vec<_>>(), &[4, 5]);
|
||||
// drain should not change the capacity
|
||||
assert_eq!(v.capacity(), old_capacity);
|
||||
|
||||
// Exercise the tail-shifting code when in the inline state
|
||||
// This has the potential to produce UB due to aliasing
|
||||
let mut v: SmallVec<[u8; 2]> = SmallVec::new();
|
||||
v.push(1);
|
||||
v.push(2);
|
||||
assert_eq!(v.drain(..1).collect::<Vec<_>>(), &[1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drain_rev() {
|
||||
let mut v: SmallVec<[u8; 2]> = SmallVec::new();
|
||||
v.push(3);
|
||||
assert_eq!(v.drain(..).rev().collect::<Vec<_>>(), &[3]);
|
||||
|
||||
// spilling the vec
|
||||
v.push(3);
|
||||
v.push(4);
|
||||
v.push(5);
|
||||
assert_eq!(v.drain(..).rev().collect::<Vec<_>>(), &[5, 4, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drain_forget() {
|
||||
let mut v: SmallVec<[u8; 1]> = smallvec![0, 1, 2, 3, 4, 5, 6, 7];
|
||||
std::mem::forget(v.drain(2..5));
|
||||
assert_eq!(v.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_iter() {
|
||||
let mut v: SmallVec<[u8; 2]> = SmallVec::new();
|
||||
v.push(3);
|
||||
assert_eq!(v.into_iter().collect::<Vec<_>>(), &[3]);
|
||||
|
||||
// spilling the vec
|
||||
let mut v: SmallVec<[u8; 2]> = SmallVec::new();
|
||||
v.push(3);
|
||||
v.push(4);
|
||||
v.push(5);
|
||||
assert_eq!(v.into_iter().collect::<Vec<_>>(), &[3, 4, 5]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_iter_rev() {
|
||||
let mut v: SmallVec<[u8; 2]> = SmallVec::new();
|
||||
v.push(3);
|
||||
assert_eq!(v.into_iter().rev().collect::<Vec<_>>(), &[3]);
|
||||
|
||||
// spilling the vec
|
||||
let mut v: SmallVec<[u8; 2]> = SmallVec::new();
|
||||
v.push(3);
|
||||
v.push(4);
|
||||
v.push(5);
|
||||
assert_eq!(v.into_iter().rev().collect::<Vec<_>>(), &[5, 4, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_iter_drop() {
|
||||
use std::cell::Cell;
|
||||
|
||||
struct DropCounter<'a>(&'a Cell<i32>);
|
||||
|
||||
impl<'a> Drop for DropCounter<'a> {
|
||||
fn drop(&mut self) {
|
||||
self.0.set(self.0.get() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let cell = Cell::new(0);
|
||||
let mut v: SmallVec<[DropCounter<'_>; 2]> = SmallVec::new();
|
||||
v.push(DropCounter(&cell));
|
||||
v.into_iter();
|
||||
assert_eq!(cell.get(), 1);
|
||||
}
|
||||
|
||||
{
|
||||
let cell = Cell::new(0);
|
||||
let mut v: SmallVec<[DropCounter<'_>; 2]> = SmallVec::new();
|
||||
v.push(DropCounter(&cell));
|
||||
v.push(DropCounter(&cell));
|
||||
assert!(v.into_iter().next().is_some());
|
||||
assert_eq!(cell.get(), 2);
|
||||
}
|
||||
|
||||
{
|
||||
let cell = Cell::new(0);
|
||||
let mut v: SmallVec<[DropCounter<'_>; 2]> = SmallVec::new();
|
||||
v.push(DropCounter(&cell));
|
||||
v.push(DropCounter(&cell));
|
||||
v.push(DropCounter(&cell));
|
||||
assert!(v.into_iter().next().is_some());
|
||||
assert_eq!(cell.get(), 3);
|
||||
}
|
||||
{
|
||||
let cell = Cell::new(0);
|
||||
let mut v: SmallVec<[DropCounter<'_>; 2]> = SmallVec::new();
|
||||
v.push(DropCounter(&cell));
|
||||
v.push(DropCounter(&cell));
|
||||
v.push(DropCounter(&cell));
|
||||
{
|
||||
let mut it = v.into_iter();
|
||||
assert!(it.next().is_some());
|
||||
assert!(it.next_back().is_some());
|
||||
}
|
||||
assert_eq!(cell.get(), 3);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_capacity() {
|
||||
let mut v: SmallVec<[u8; 2]> = SmallVec::new();
|
||||
v.reserve(1);
|
||||
assert_eq!(v.capacity(), 2);
|
||||
assert!(!v.spilled());
|
||||
|
||||
v.reserve_exact(0x100);
|
||||
assert!(v.capacity() >= 0x100);
|
||||
|
||||
v.push(0);
|
||||
v.push(1);
|
||||
v.push(2);
|
||||
v.push(3);
|
||||
|
||||
v.shrink_to_fit();
|
||||
assert!(v.capacity() < 0x100);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_truncate() {
|
||||
let mut v: SmallVec<[Box<u8>; 8]> = SmallVec::new();
|
||||
|
||||
for x in 0..8 {
|
||||
v.push(Box::new(x));
|
||||
}
|
||||
v.truncate(4);
|
||||
|
||||
assert_eq!(v.len(), 4);
|
||||
assert!(!v.spilled());
|
||||
|
||||
assert_eq!(*v.swap_remove(1), 1);
|
||||
assert_eq!(*v.remove(1), 3);
|
||||
v.insert(1, Box::new(3));
|
||||
|
||||
assert_eq!(&v.iter().map(|v| **v).collect::<Vec<_>>(), &[0, 3, 2]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_insert_many() {
|
||||
let mut v: SmallVec<[u8; 8]> = SmallVec::new();
|
||||
for x in 0..4 {
|
||||
v.push(x);
|
||||
}
|
||||
assert_eq!(v.len(), 4);
|
||||
v.insert_many(1, [5, 6].iter().cloned());
|
||||
assert_eq!(
|
||||
&v.iter().map(|v| *v).collect::<Vec<_>>(),
|
||||
&[0, 5, 6, 1, 2, 3]
|
||||
);
|
||||
}
|
||||
|
||||
struct MockHintIter<T: Iterator> {
|
||||
x: T,
|
||||
hint: usize,
|
||||
}
|
||||
impl<T: Iterator> Iterator for MockHintIter<T> {
|
||||
type Item = T::Item;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.x.next()
|
||||
}
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(self.hint, None)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_insert_many_short_hint() {
|
||||
let mut v: SmallVec<[u8; 8]> = SmallVec::new();
|
||||
for x in 0..4 {
|
||||
v.push(x);
|
||||
}
|
||||
assert_eq!(v.len(), 4);
|
||||
v.insert_many(
|
||||
1,
|
||||
MockHintIter {
|
||||
x: [5, 6].iter().cloned(),
|
||||
hint: 5,
|
||||
},
|
||||
);
|
||||
assert_eq!(
|
||||
&v.iter().map(|v| *v).collect::<Vec<_>>(),
|
||||
&[0, 5, 6, 1, 2, 3]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_insert_many_long_hint() {
|
||||
let mut v: SmallVec<[u8; 8]> = SmallVec::new();
|
||||
for x in 0..4 {
|
||||
v.push(x);
|
||||
}
|
||||
assert_eq!(v.len(), 4);
|
||||
v.insert_many(
|
||||
1,
|
||||
MockHintIter {
|
||||
x: [5, 6].iter().cloned(),
|
||||
hint: 1,
|
||||
},
|
||||
);
|
||||
assert_eq!(
|
||||
&v.iter().map(|v| *v).collect::<Vec<_>>(),
|
||||
&[0, 5, 6, 1, 2, 3]
|
||||
);
|
||||
}
|
||||
|
||||
// https://github.com/servo/rust-smallvec/issues/96
|
||||
mod insert_many_panic {
|
||||
use crate::{smallvec, SmallVec};
|
||||
use alloc::boxed::Box;
|
||||
|
||||
struct PanicOnDoubleDrop {
|
||||
dropped: Box<bool>,
|
||||
}
|
||||
|
||||
impl PanicOnDoubleDrop {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
dropped: Box::new(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for PanicOnDoubleDrop {
|
||||
fn drop(&mut self) {
|
||||
assert!(!*self.dropped, "already dropped");
|
||||
*self.dropped = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// Claims to yield `hint` items, but actually yields `count`, then panics.
|
||||
struct BadIter {
|
||||
hint: usize,
|
||||
count: usize,
|
||||
}
|
||||
|
||||
impl Iterator for BadIter {
|
||||
type Item = PanicOnDoubleDrop;
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(self.hint, None)
|
||||
}
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.count == 0 {
|
||||
panic!()
|
||||
}
|
||||
self.count -= 1;
|
||||
Some(PanicOnDoubleDrop::new())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn panic_early_at_start() {
|
||||
let mut vec: SmallVec<[PanicOnDoubleDrop; 0]> =
|
||||
smallvec![PanicOnDoubleDrop::new(), PanicOnDoubleDrop::new(),];
|
||||
let result = ::std::panic::catch_unwind(move || {
|
||||
vec.insert_many(0, BadIter { hint: 1, count: 0 });
|
||||
});
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn panic_early_in_middle() {
|
||||
let mut vec: SmallVec<[PanicOnDoubleDrop; 0]> =
|
||||
smallvec![PanicOnDoubleDrop::new(), PanicOnDoubleDrop::new(),];
|
||||
let result = ::std::panic::catch_unwind(move || {
|
||||
vec.insert_many(1, BadIter { hint: 4, count: 2 });
|
||||
});
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn panic_early_at_end() {
|
||||
let mut vec: SmallVec<[PanicOnDoubleDrop; 0]> =
|
||||
smallvec![PanicOnDoubleDrop::new(), PanicOnDoubleDrop::new(),];
|
||||
let result = ::std::panic::catch_unwind(move || {
|
||||
vec.insert_many(2, BadIter { hint: 3, count: 1 });
|
||||
});
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn panic_late_at_start() {
|
||||
let mut vec: SmallVec<[PanicOnDoubleDrop; 0]> =
|
||||
smallvec![PanicOnDoubleDrop::new(), PanicOnDoubleDrop::new(),];
|
||||
let result = ::std::panic::catch_unwind(move || {
|
||||
vec.insert_many(0, BadIter { hint: 3, count: 5 });
|
||||
});
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn panic_late_at_end() {
|
||||
let mut vec: SmallVec<[PanicOnDoubleDrop; 0]> =
|
||||
smallvec![PanicOnDoubleDrop::new(), PanicOnDoubleDrop::new(),];
|
||||
let result = ::std::panic::catch_unwind(move || {
|
||||
vec.insert_many(2, BadIter { hint: 3, count: 5 });
|
||||
});
|
||||
assert!(result.is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_invalid_grow() {
|
||||
let mut v: SmallVec<[u8; 8]> = SmallVec::new();
|
||||
v.extend(0..8);
|
||||
v.grow(5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn drain_overflow() {
|
||||
let mut v: SmallVec<[u8; 8]> = smallvec![0];
|
||||
v.drain(..=std::usize::MAX);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_insert_from_slice() {
|
||||
let mut v: SmallVec<[u8; 8]> = SmallVec::new();
|
||||
for x in 0..4 {
|
||||
v.push(x);
|
||||
}
|
||||
assert_eq!(v.len(), 4);
|
||||
v.insert_from_slice(1, &[5, 6]);
|
||||
assert_eq!(
|
||||
&v.iter().map(|v| *v).collect::<Vec<_>>(),
|
||||
&[0, 5, 6, 1, 2, 3]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extend_from_slice() {
|
||||
let mut v: SmallVec<[u8; 8]> = SmallVec::new();
|
||||
for x in 0..4 {
|
||||
v.push(x);
|
||||
}
|
||||
assert_eq!(v.len(), 4);
|
||||
v.extend_from_slice(&[5, 6]);
|
||||
assert_eq!(
|
||||
&v.iter().map(|v| *v).collect::<Vec<_>>(),
|
||||
&[0, 1, 2, 3, 5, 6]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_drop_panic_smallvec() {
|
||||
// This test should only panic once, and not double panic,
|
||||
// which would mean a double drop
|
||||
struct DropPanic;
|
||||
|
||||
impl Drop for DropPanic {
|
||||
fn drop(&mut self) {
|
||||
panic!("drop");
|
||||
}
|
||||
}
|
||||
|
||||
let mut v = SmallVec::<[_; 1]>::new();
|
||||
v.push(DropPanic);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_eq() {
|
||||
let mut a: SmallVec<[u32; 2]> = SmallVec::new();
|
||||
let mut b: SmallVec<[u32; 2]> = SmallVec::new();
|
||||
let mut c: SmallVec<[u32; 2]> = SmallVec::new();
|
||||
// a = [1, 2]
|
||||
a.push(1);
|
||||
a.push(2);
|
||||
// b = [1, 2]
|
||||
b.push(1);
|
||||
b.push(2);
|
||||
// c = [3, 4]
|
||||
c.push(3);
|
||||
c.push(4);
|
||||
|
||||
assert!(a == b);
|
||||
assert!(a != c);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ord() {
|
||||
let mut a: SmallVec<[u32; 2]> = SmallVec::new();
|
||||
let mut b: SmallVec<[u32; 2]> = SmallVec::new();
|
||||
let mut c: SmallVec<[u32; 2]> = SmallVec::new();
|
||||
// a = [1]
|
||||
a.push(1);
|
||||
// b = [1, 1]
|
||||
b.push(1);
|
||||
b.push(1);
|
||||
// c = [1, 2]
|
||||
c.push(1);
|
||||
c.push(2);
|
||||
|
||||
assert!(a < b);
|
||||
assert!(b > a);
|
||||
assert!(b < c);
|
||||
assert!(c > b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hash() {
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::Hash;
|
||||
|
||||
{
|
||||
let mut a: SmallVec<[u32; 2]> = SmallVec::new();
|
||||
let b = [1, 2];
|
||||
a.extend(b.iter().cloned());
|
||||
let mut hasher = DefaultHasher::new();
|
||||
assert_eq!(a.hash(&mut hasher), b.hash(&mut hasher));
|
||||
}
|
||||
{
|
||||
let mut a: SmallVec<[u32; 2]> = SmallVec::new();
|
||||
let b = [1, 2, 11, 12];
|
||||
a.extend(b.iter().cloned());
|
||||
let mut hasher = DefaultHasher::new();
|
||||
assert_eq!(a.hash(&mut hasher), b.hash(&mut hasher));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_as_ref() {
|
||||
let mut a: SmallVec<[u32; 2]> = SmallVec::new();
|
||||
a.push(1);
|
||||
assert_eq!(a.as_ref(), [1]);
|
||||
a.push(2);
|
||||
assert_eq!(a.as_ref(), [1, 2]);
|
||||
a.push(3);
|
||||
assert_eq!(a.as_ref(), [1, 2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_as_mut() {
|
||||
let mut a: SmallVec<[u32; 2]> = SmallVec::new();
|
||||
a.push(1);
|
||||
assert_eq!(a.as_mut(), [1]);
|
||||
a.push(2);
|
||||
assert_eq!(a.as_mut(), [1, 2]);
|
||||
a.push(3);
|
||||
assert_eq!(a.as_mut(), [1, 2, 3]);
|
||||
a.as_mut()[1] = 4;
|
||||
assert_eq!(a.as_mut(), [1, 4, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_borrow() {
|
||||
use std::borrow::Borrow;
|
||||
|
||||
let mut a: SmallVec<[u32; 2]> = SmallVec::new();
|
||||
a.push(1);
|
||||
assert_eq!(a.borrow(), [1]);
|
||||
a.push(2);
|
||||
assert_eq!(a.borrow(), [1, 2]);
|
||||
a.push(3);
|
||||
assert_eq!(a.borrow(), [1, 2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_borrow_mut() {
|
||||
use std::borrow::BorrowMut;
|
||||
|
||||
let mut a: SmallVec<[u32; 2]> = SmallVec::new();
|
||||
a.push(1);
|
||||
assert_eq!(a.borrow_mut(), [1]);
|
||||
a.push(2);
|
||||
assert_eq!(a.borrow_mut(), [1, 2]);
|
||||
a.push(3);
|
||||
assert_eq!(a.borrow_mut(), [1, 2, 3]);
|
||||
BorrowMut::<[u32]>::borrow_mut(&mut a)[1] = 4;
|
||||
assert_eq!(a.borrow_mut(), [1, 4, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from() {
|
||||
assert_eq!(&SmallVec::<[u32; 2]>::from(&[1][..])[..], [1]);
|
||||
assert_eq!(&SmallVec::<[u32; 2]>::from(&[1, 2, 3][..])[..], [1, 2, 3]);
|
||||
|
||||
let vec = vec![];
|
||||
let small_vec: SmallVec<[u8; 3]> = SmallVec::from(vec);
|
||||
assert_eq!(&*small_vec, &[]);
|
||||
drop(small_vec);
|
||||
|
||||
let vec = vec![1, 2, 3, 4, 5];
|
||||
let small_vec: SmallVec<[u8; 3]> = SmallVec::from(vec);
|
||||
assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]);
|
||||
drop(small_vec);
|
||||
|
||||
let vec = vec![1, 2, 3, 4, 5];
|
||||
let small_vec: SmallVec<[u8; 1]> = SmallVec::from(vec);
|
||||
assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]);
|
||||
drop(small_vec);
|
||||
|
||||
let array = [1];
|
||||
let small_vec: SmallVec<[u8; 1]> = SmallVec::from(array);
|
||||
assert_eq!(&*small_vec, &[1]);
|
||||
drop(small_vec);
|
||||
|
||||
let array = [99; 128];
|
||||
let small_vec: SmallVec<[u8; 128]> = SmallVec::from(array);
|
||||
assert_eq!(&*small_vec, vec![99u8; 128].as_slice());
|
||||
drop(small_vec);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_slice() {
|
||||
assert_eq!(&SmallVec::<[u32; 2]>::from_slice(&[1][..])[..], [1]);
|
||||
assert_eq!(
|
||||
&SmallVec::<[u32; 2]>::from_slice(&[1, 2, 3][..])[..],
|
||||
[1, 2, 3]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_exact_size_iterator() {
|
||||
let mut vec = SmallVec::<[u32; 2]>::from(&[1, 2, 3][..]);
|
||||
assert_eq!(vec.clone().into_iter().len(), 3);
|
||||
assert_eq!(vec.drain(..2).len(), 2);
|
||||
assert_eq!(vec.into_iter().len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_into_iter_as_slice() {
|
||||
let vec = SmallVec::<[u32; 2]>::from(&[1, 2, 3][..]);
|
||||
let mut iter = vec.clone().into_iter();
|
||||
assert_eq!(iter.as_slice(), &[1, 2, 3]);
|
||||
assert_eq!(iter.as_mut_slice(), &[1, 2, 3]);
|
||||
iter.next();
|
||||
assert_eq!(iter.as_slice(), &[2, 3]);
|
||||
assert_eq!(iter.as_mut_slice(), &[2, 3]);
|
||||
iter.next_back();
|
||||
assert_eq!(iter.as_slice(), &[2]);
|
||||
assert_eq!(iter.as_mut_slice(), &[2]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_into_iter_clone() {
|
||||
// Test that the cloned iterator yields identical elements and that it owns its own copy
|
||||
// (i.e. no use after move errors).
|
||||
let mut iter = SmallVec::<[u8; 2]>::from_iter(0..3).into_iter();
|
||||
let mut clone_iter = iter.clone();
|
||||
while let Some(x) = iter.next() {
|
||||
assert_eq!(x, clone_iter.next().unwrap());
|
||||
}
|
||||
assert_eq!(clone_iter.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_into_iter_clone_partially_consumed_iterator() {
|
||||
// Test that the cloned iterator only contains the remaining elements of the original iterator.
|
||||
let mut iter = SmallVec::<[u8; 2]>::from_iter(0..3).into_iter().skip(1);
|
||||
let mut clone_iter = iter.clone();
|
||||
while let Some(x) = iter.next() {
|
||||
assert_eq!(x, clone_iter.next().unwrap());
|
||||
}
|
||||
assert_eq!(clone_iter.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_into_iter_clone_empty_smallvec() {
|
||||
let mut iter = SmallVec::<[u8; 2]>::new().into_iter();
|
||||
let mut clone_iter = iter.clone();
|
||||
assert_eq!(iter.next(), None);
|
||||
assert_eq!(clone_iter.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shrink_to_fit_unspill() {
|
||||
let mut vec = SmallVec::<[u8; 2]>::from_iter(0..3);
|
||||
vec.pop();
|
||||
assert!(vec.spilled());
|
||||
vec.shrink_to_fit();
|
||||
assert!(!vec.spilled(), "shrink_to_fit will un-spill if possible");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_into_vec() {
|
||||
let vec = SmallVec::<[u8; 2]>::from_iter(0..2);
|
||||
assert_eq!(vec.into_vec(), vec![0, 1]);
|
||||
|
||||
let vec = SmallVec::<[u8; 2]>::from_iter(0..3);
|
||||
assert_eq!(vec.into_vec(), vec![0, 1, 2]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_into_inner() {
|
||||
let vec = SmallVec::<[u8; 2]>::from_iter(0..2);
|
||||
assert_eq!(vec.into_inner(), Ok([0, 1]));
|
||||
|
||||
let vec = SmallVec::<[u8; 2]>::from_iter(0..1);
|
||||
assert_eq!(vec.clone().into_inner(), Err(vec));
|
||||
|
||||
let vec = SmallVec::<[u8; 2]>::from_iter(0..3);
|
||||
assert_eq!(vec.clone().into_inner(), Err(vec));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_vec() {
|
||||
let vec = vec![];
|
||||
let small_vec: SmallVec<[u8; 3]> = SmallVec::from_vec(vec);
|
||||
assert_eq!(&*small_vec, &[]);
|
||||
drop(small_vec);
|
||||
|
||||
let vec = vec![];
|
||||
let small_vec: SmallVec<[u8; 1]> = SmallVec::from_vec(vec);
|
||||
assert_eq!(&*small_vec, &[]);
|
||||
drop(small_vec);
|
||||
|
||||
let vec = vec![1];
|
||||
let small_vec: SmallVec<[u8; 3]> = SmallVec::from_vec(vec);
|
||||
assert_eq!(&*small_vec, &[1]);
|
||||
drop(small_vec);
|
||||
|
||||
let vec = vec![1, 2, 3];
|
||||
let small_vec: SmallVec<[u8; 3]> = SmallVec::from_vec(vec);
|
||||
assert_eq!(&*small_vec, &[1, 2, 3]);
|
||||
drop(small_vec);
|
||||
|
||||
let vec = vec![1, 2, 3, 4, 5];
|
||||
let small_vec: SmallVec<[u8; 3]> = SmallVec::from_vec(vec);
|
||||
assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]);
|
||||
drop(small_vec);
|
||||
|
||||
let vec = vec![1, 2, 3, 4, 5];
|
||||
let small_vec: SmallVec<[u8; 1]> = SmallVec::from_vec(vec);
|
||||
assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]);
|
||||
drop(small_vec);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_retain() {
|
||||
// Test inline data storate
|
||||
let mut sv: SmallVec<[i32; 5]> = SmallVec::from_slice(&[1, 2, 3, 3, 4]);
|
||||
sv.retain(|&mut i| i != 3);
|
||||
assert_eq!(sv.pop(), Some(4));
|
||||
assert_eq!(sv.pop(), Some(2));
|
||||
assert_eq!(sv.pop(), Some(1));
|
||||
assert_eq!(sv.pop(), None);
|
||||
|
||||
// Test spilled data storage
|
||||
let mut sv: SmallVec<[i32; 3]> = SmallVec::from_slice(&[1, 2, 3, 3, 4]);
|
||||
sv.retain(|&mut i| i != 3);
|
||||
assert_eq!(sv.pop(), Some(4));
|
||||
assert_eq!(sv.pop(), Some(2));
|
||||
assert_eq!(sv.pop(), Some(1));
|
||||
assert_eq!(sv.pop(), None);
|
||||
|
||||
// Test that drop implementations are called for inline.
|
||||
let one = Rc::new(1);
|
||||
let mut sv: SmallVec<[Rc<i32>; 3]> = SmallVec::new();
|
||||
sv.push(Rc::clone(&one));
|
||||
assert_eq!(Rc::strong_count(&one), 2);
|
||||
sv.retain(|_| false);
|
||||
assert_eq!(Rc::strong_count(&one), 1);
|
||||
|
||||
// Test that drop implementations are called for spilled data.
|
||||
let mut sv: SmallVec<[Rc<i32>; 1]> = SmallVec::new();
|
||||
sv.push(Rc::clone(&one));
|
||||
sv.push(Rc::new(2));
|
||||
assert_eq!(Rc::strong_count(&one), 2);
|
||||
sv.retain(|_| false);
|
||||
assert_eq!(Rc::strong_count(&one), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dedup() {
|
||||
let mut dupes: SmallVec<[i32; 5]> = SmallVec::from_slice(&[1, 1, 2, 3, 3]);
|
||||
dupes.dedup();
|
||||
assert_eq!(&*dupes, &[1, 2, 3]);
|
||||
|
||||
let mut empty: SmallVec<[i32; 5]> = SmallVec::new();
|
||||
empty.dedup();
|
||||
assert!(empty.is_empty());
|
||||
|
||||
let mut all_ones: SmallVec<[i32; 5]> = SmallVec::from_slice(&[1, 1, 1, 1, 1]);
|
||||
all_ones.dedup();
|
||||
assert_eq!(all_ones.len(), 1);
|
||||
|
||||
let mut no_dupes: SmallVec<[i32; 5]> = SmallVec::from_slice(&[1, 2, 3, 4, 5]);
|
||||
no_dupes.dedup();
|
||||
assert_eq!(no_dupes.len(), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_resize() {
|
||||
let mut v: SmallVec<[i32; 8]> = SmallVec::new();
|
||||
v.push(1);
|
||||
v.resize(5, 0);
|
||||
assert_eq!(v[..], [1, 0, 0, 0, 0][..]);
|
||||
|
||||
v.resize(2, -1);
|
||||
assert_eq!(v[..], [1, 0][..]);
|
||||
}
|
||||
|
||||
#[cfg(feature = "write")]
|
||||
#[test]
|
||||
fn test_write() {
|
||||
use std::io::Write;
|
||||
|
||||
let data = [1, 2, 3, 4, 5];
|
||||
|
||||
let mut small_vec: SmallVec<[u8; 2]> = SmallVec::new();
|
||||
let len = small_vec.write(&data[..]).unwrap();
|
||||
assert_eq!(len, 5);
|
||||
assert_eq!(small_vec.as_ref(), data.as_ref());
|
||||
|
||||
let mut small_vec: SmallVec<[u8; 2]> = SmallVec::new();
|
||||
small_vec.write_all(&data[..]).unwrap();
|
||||
assert_eq!(small_vec.as_ref(), data.as_ref());
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
extern crate bincode;
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
#[test]
|
||||
fn test_serde() {
|
||||
use self::bincode::{config, deserialize};
|
||||
let mut small_vec: SmallVec<[i32; 2]> = SmallVec::new();
|
||||
small_vec.push(1);
|
||||
let encoded = config().limit(100).serialize(&small_vec).unwrap();
|
||||
let decoded: SmallVec<[i32; 2]> = deserialize(&encoded).unwrap();
|
||||
assert_eq!(small_vec, decoded);
|
||||
small_vec.push(2);
|
||||
// Spill the vec
|
||||
small_vec.push(3);
|
||||
small_vec.push(4);
|
||||
// Check again after spilling.
|
||||
let encoded = config().limit(100).serialize(&small_vec).unwrap();
|
||||
let decoded: SmallVec<[i32; 2]> = deserialize(&encoded).unwrap();
|
||||
assert_eq!(small_vec, decoded);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn grow_to_shrink() {
|
||||
let mut v: SmallVec<[u8; 2]> = SmallVec::new();
|
||||
v.push(1);
|
||||
v.push(2);
|
||||
v.push(3);
|
||||
assert!(v.spilled());
|
||||
v.clear();
|
||||
// Shrink to inline.
|
||||
v.grow(2);
|
||||
assert!(!v.spilled());
|
||||
assert_eq!(v.capacity(), 2);
|
||||
assert_eq!(v.len(), 0);
|
||||
v.push(4);
|
||||
assert_eq!(v[..], [4]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resumable_extend() {
|
||||
let s = "a b c";
|
||||
// This iterator yields: (Some('a'), None, Some('b'), None, Some('c')), None
|
||||
let it = s
|
||||
.chars()
|
||||
.scan(0, |_, ch| if ch.is_whitespace() { None } else { Some(ch) });
|
||||
let mut v: SmallVec<[char; 4]> = SmallVec::new();
|
||||
v.extend(it);
|
||||
assert_eq!(v[..], ['a']);
|
||||
}
|
||||
|
||||
// #139
|
||||
#[test]
|
||||
fn uninhabited() {
|
||||
enum Void {}
|
||||
let _sv = SmallVec::<[Void; 8]>::new();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn grow_spilled_same_size() {
|
||||
let mut v: SmallVec<[u8; 2]> = SmallVec::new();
|
||||
v.push(0);
|
||||
v.push(1);
|
||||
v.push(2);
|
||||
assert!(v.spilled());
|
||||
assert_eq!(v.capacity(), 4);
|
||||
// grow with the same capacity
|
||||
v.grow(4);
|
||||
assert_eq!(v.capacity(), 4);
|
||||
assert_eq!(v[..], [0, 1, 2]);
|
||||
}
|
||||
|
||||
#[cfg(feature = "const_generics")]
|
||||
#[test]
|
||||
fn const_generics() {
|
||||
let _v = SmallVec::<[i32; 987]>::default();
|
||||
}
|
||||
|
||||
#[cfg(feature = "const_new")]
|
||||
#[test]
|
||||
fn const_new() {
|
||||
let v = const_new_inner();
|
||||
assert_eq!(v.capacity(), 4);
|
||||
assert_eq!(v.len(), 0);
|
||||
let v = const_new_inline_sized();
|
||||
assert_eq!(v.capacity(), 4);
|
||||
assert_eq!(v.len(), 4);
|
||||
assert_eq!(v[0], 1);
|
||||
let v = const_new_inline_args();
|
||||
assert_eq!(v.capacity(), 2);
|
||||
assert_eq!(v.len(), 2);
|
||||
assert_eq!(v[0], 1);
|
||||
assert_eq!(v[1], 4);
|
||||
}
|
||||
#[cfg(feature = "const_new")]
|
||||
const fn const_new_inner() -> SmallVec<[i32; 4]> {
|
||||
SmallVec::<[i32; 4]>::new_const()
|
||||
}
|
||||
#[cfg(feature = "const_new")]
|
||||
const fn const_new_inline_sized() -> SmallVec<[i32; 4]> {
|
||||
crate::smallvec_inline![1; 4]
|
||||
}
|
||||
#[cfg(feature = "const_new")]
|
||||
const fn const_new_inline_args() -> SmallVec<[i32; 2]> {
|
||||
crate::smallvec_inline![1, 4]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_macro() {
|
||||
let _v: SmallVec<[u8; 1]> = smallvec![];
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_size_items() {
|
||||
SmallVec::<[(); 0]>::new().push(());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_insert_many_overflow() {
|
||||
let mut v: SmallVec<[u8; 1]> = SmallVec::new();
|
||||
v.push(123);
|
||||
|
||||
// Prepare an iterator with small lower bound
|
||||
let iter = (0u8..5).filter(|n| n % 2 == 0);
|
||||
assert_eq!(iter.size_hint().0, 0);
|
||||
|
||||
v.insert_many(0, iter);
|
||||
assert_eq!(&*v, &[0, 2, 4, 123]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_clone_from() {
|
||||
let mut a: SmallVec<[u8; 2]> = SmallVec::new();
|
||||
a.push(1);
|
||||
a.push(2);
|
||||
a.push(3);
|
||||
|
||||
let mut b: SmallVec<[u8; 2]> = SmallVec::new();
|
||||
b.push(10);
|
||||
|
||||
let mut c: SmallVec<[u8; 2]> = SmallVec::new();
|
||||
c.push(20);
|
||||
c.push(21);
|
||||
c.push(22);
|
||||
|
||||
a.clone_from(&b);
|
||||
assert_eq!(&*a, &[10]);
|
||||
|
||||
b.clone_from(&c);
|
||||
assert_eq!(&*b, &[20, 21, 22]);
|
||||
}
|
||||
68
clamav/libclamav_rust/.cargo/vendor/smallvec/tests/debugger_visualizer.rs
vendored
Normal file
68
clamav/libclamav_rust/.cargo/vendor/smallvec/tests/debugger_visualizer.rs
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
use debugger_test::debugger_test;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
||||
#[inline(never)]
|
||||
fn __break() {}
|
||||
|
||||
#[debugger_test(
|
||||
debugger = "cdb",
|
||||
commands = r#"
|
||||
.nvlist
|
||||
dx sv
|
||||
|
||||
g
|
||||
|
||||
dx sv
|
||||
|
||||
g
|
||||
|
||||
dx sv
|
||||
"#,
|
||||
expected_statements = r#"
|
||||
sv : { len=0x2 } [Type: smallvec::SmallVec<array$<i32,4> >]
|
||||
[<Raw View>] [Type: smallvec::SmallVec<array$<i32,4> >]
|
||||
[capacity] : 4
|
||||
[len] : 0x2 [Type: unsigned __int64]
|
||||
[0] : 1 [Type: int]
|
||||
[1] : 2 [Type: int]
|
||||
|
||||
sv : { len=0x5 } [Type: smallvec::SmallVec<array$<i32,4> >]
|
||||
[<Raw View>] [Type: smallvec::SmallVec<array$<i32,4> >]
|
||||
[capacity] : 0x8 [Type: unsigned __int64]
|
||||
[len] : 0x5 [Type: unsigned __int64]
|
||||
[0] : 5 [Type: int]
|
||||
[1] : 2 [Type: int]
|
||||
[2] : 3 [Type: int]
|
||||
[3] : 4 [Type: int]
|
||||
[4] : 5 [Type: int]
|
||||
|
||||
sv : { len=0x5 } [Type: smallvec::SmallVec<array$<i32,4> >]
|
||||
[<Raw View>] [Type: smallvec::SmallVec<array$<i32,4> >]
|
||||
[capacity] : 0x8 [Type: unsigned __int64]
|
||||
[len] : 0x5 [Type: unsigned __int64]
|
||||
[0] : 2 [Type: int]
|
||||
[1] : 3 [Type: int]
|
||||
[2] : 4 [Type: int]
|
||||
[3] : 5 [Type: int]
|
||||
[4] : 5 [Type: int]
|
||||
"#
|
||||
)]
|
||||
#[inline(never)]
|
||||
fn test_debugger_visualizer() {
|
||||
// This SmallVec can hold up to 4 items on the stack:
|
||||
let mut sv: SmallVec<[i32; 4]> = smallvec![1, 2];
|
||||
__break();
|
||||
|
||||
// Overfill the SmallVec to move its contents to the heap
|
||||
for i in 3..6 {
|
||||
sv.push(i);
|
||||
}
|
||||
|
||||
// Update the contents of the first value of the SmallVec.
|
||||
sv[0] = sv[1] + sv[2];
|
||||
__break();
|
||||
|
||||
// Sort the SmallVec in place.
|
||||
sv.sort();
|
||||
__break();
|
||||
}
|
||||
24
clamav/libclamav_rust/.cargo/vendor/smallvec/tests/macro.rs
vendored
Normal file
24
clamav/libclamav_rust/.cargo/vendor/smallvec/tests/macro.rs
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
/// This file tests `smallvec!` without actually having the macro in scope.
|
||||
/// This forces any recursion to use a `$crate` prefix to reliably find itself.
|
||||
|
||||
#[test]
|
||||
fn smallvec() {
|
||||
let mut vec: smallvec::SmallVec<[i32; 2]>;
|
||||
|
||||
macro_rules! check {
|
||||
($init:tt) => {
|
||||
vec = smallvec::smallvec! $init;
|
||||
assert_eq!(*vec, *vec! $init);
|
||||
}
|
||||
}
|
||||
|
||||
check!([0; 0]);
|
||||
check!([1; 1]);
|
||||
check!([2; 2]);
|
||||
check!([3; 3]);
|
||||
|
||||
check!([]);
|
||||
check!([1]);
|
||||
check!([1, 2]);
|
||||
check!([1, 2, 3]);
|
||||
}
|
||||
Reference in New Issue
Block a user