lkml.org 
[lkml]   [2023]   [Feb]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Date
    Subject[PATCH 1/4] rust: Import upstream `alloc::vec::set_len_on_drop` module
    This is a subset of the Rust standard library `alloc` crate,
    version 1.66.0, licensed under "Apache-2.0 OR MIT", from:

    https://github.com/rust-lang/rust/tree/1.66.0/library/alloc/src

    The file is copied as-is, with no modifications whatsoever
    (not even adding the SPDX identifiers).

    For copyright details, please see:

    https://github.com/rust-lang/rust/blob/1.66.0/COPYRIGHT

    Signed-off-by: Asahi Lina <lina@asahilina.net>
    ---
    rust/alloc/vec/set_len_on_drop.rs | 28 ++++++++++++++++++++++++++++
    1 file changed, 28 insertions(+)

    diff --git a/rust/alloc/vec/set_len_on_drop.rs b/rust/alloc/vec/set_len_on_drop.rs
    new file mode 100644
    index 000000000000..8b66bc812129
    --- /dev/null
    +++ b/rust/alloc/vec/set_len_on_drop.rs
    @@ -0,0 +1,28 @@
    +// Set the length of the vec when the `SetLenOnDrop` value goes out of scope.
    +//
    +// The idea is: The length field in SetLenOnDrop is a local variable
    +// that the optimizer will see does not alias with any stores through the Vec's data
    +// pointer. This is a workaround for alias analysis issue #32155
    +pub(super) struct SetLenOnDrop<'a> {
    + len: &'a mut usize,
    + local_len: usize,
    +}
    +
    +impl<'a> SetLenOnDrop<'a> {
    + #[inline]
    + pub(super) fn new(len: &'a mut usize) -> Self {
    + SetLenOnDrop { local_len: *len, len }
    + }
    +
    + #[inline]
    + pub(super) fn increment_len(&mut self, increment: usize) {
    + self.local_len += increment;
    + }
    +}
    +
    +impl Drop for SetLenOnDrop<'_> {
    + #[inline]
    + fn drop(&mut self) {
    + *self.len = self.local_len;
    + }
    +}
    --
    2.35.1

    \
     
     \ /
      Last update: 2023-03-27 00:34    [W:3.655 / U:0.104 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site