• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vortex-data / vortex / 16728097825

04 Aug 2025 04:00PM UTC coverage: 48.355% (-35.1%) from 83.429%
16728097825

Pull #4108

github

web-flow
Merge 1b2d27fd8 into 649ba9576
Pull Request #4108: perf[vortex-array]: use all_valid instead of `invalid_count() == 0`

1 of 1 new or added line in 1 file covered. (100.0%)

11596 existing lines in 378 files now uncovered.

18635 of 38538 relevant lines covered (48.35%)

151786.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/vortex-buffer/src/bytes.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use bytes::Buf;
5
use vortex_error::VortexExpect;
6

7
use crate::{Alignment, ByteBuffer, ConstBuffer, ConstByteBuffer};
8

9
/// An extension to the [`Buf`] trait that provides a function `copy_to_aligned` similar to
10
/// `copy_to_bytes` that allows for zero-copy aligned reads where possible.
11
pub trait AlignedBuf: Buf {
12
    /// Copy the next `len` bytes from the buffer into a new buffer with the given alignment.
13
    /// This will be zero-copy wherever possible.
14
    ///
15
    /// The [`Buf`] trait has a specialized `copy_to_bytes` function that allows the implementation
16
    /// of `Buf` for `Bytes` and `BytesMut` to return bytes with zero-copy.
17
    ///
18
    /// This function provides similar functionality for `ByteBuffer`.
19
    ///
20
    /// TODO(ngates): what should this do the alignment of the current buffer? We have to advance
21
    ///  it by len..
UNCOV
22
    fn copy_to_aligned(&mut self, len: usize, alignment: Alignment) -> ByteBuffer {
×
23
        // The default implementation uses copy_to_bytes, and then tries to align.
24
        // When the underlying `copy_to_bytes` is zero-copy, this may perform one copy to align
25
        // the bytes. When the underlying `copy_to_bytes` is not zero-copy, this may perform two
26
        // copies.
27
        // The only way to fix this would be to invert the implementation so `copy_to_bytes`
28
        // invokes `copy_to_aligned` with an alignment of 1. But we cannot override this in the
29
        // default trait.
30
        // In practice, we tend to only call this function on `ByteBuffer: AlignedBuf`, and
31
        // therefore we have a maximum of one copy, so I'm not too worried about it.
UNCOV
32
        ByteBuffer::from(self.copy_to_bytes(len)).aligned(alignment)
×
UNCOV
33
    }
×
34

35
    /// See [`AlignedBuf::copy_to_aligned`].
UNCOV
36
    fn copy_to_const_aligned<const A: usize>(&mut self, len: usize) -> ConstByteBuffer<A> {
×
37
        // The default implementation uses copy_to_bytes, and then returns a ByteBuffer with
38
        // alignment of 1. This will be zero-copy if the underlying `copy_to_bytes` is zero-copy.
UNCOV
39
        ConstBuffer::try_from(self.copy_to_aligned(len, Alignment::new(A)))
×
UNCOV
40
            .vortex_expect("we just aligned the buffer")
×
UNCOV
41
    }
×
42
}
43

44
impl<B: Buf> AlignedBuf for B {}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc