cuprate icon indicating copy to clipboard operation
cuprate copied to clipboard

[Database] small edits to resize.rs

Open SyntheticBird45 opened this issue 9 months ago • 3 comments

  • Changed "0.0000082s" to "8.2µs" because its clearer imo
  • Removed pub marker to free functions

SyntheticBird45 avatar Apr 29 '24 17:04 SyntheticBird45

This fails to compile as the functions are private, they could be made pub(crate)

Boog900 avatar Apr 30 '24 15:04 Boog900

This fails to compile as the functions are private, they could be made pub(crate)

My bad. I didn't see heed/env.rs using fixed_bytes(). Why not replace:

// Add leeway space.
let memory_map_size = crate::resize::fixed_bytes(disk_size_bytes, 1_000_000 /* 1MB */);
env_open_options.map_size(memory_map_size.get());

by

// Add leeway space.
let memory_map_size = ResizeAlgorithm::FixedBytes(NonZeroUsize::new(1_000_000usize).unwrap()).resize(disk_size_bytes); // Import crate::resize::ResizeAlgorithm.
env_open_options.map_size(memory_map_size.get());

This seems like the intended semantic here

SyntheticBird45 avatar Apr 30 '24 15:04 SyntheticBird45

Is there a reason why these can't be pub? If they aren't necessary then the free functions should be inlined into ResizeAlgorithm + doc-tests should be moved to the appropriate variant:

pub enum ResizeAlgorithm {
    /// <insert [`monero`] doctest>
    Monero,

    /// <insert [`fixed_bytes`] doctest>
    FixedBytes(NonZeroUsize),

    /// <insert [`percent`] doctest>
    Percent(f32),
}

impl ResizeAlgorithm {
    // remove #[inline], too big
    pub fn resize(&self, current_size_bytes: usize) -> NonZeroUsize {
        match self {
            Self::Monero => /* inlined monero(current_size_bytes) */,
            Self::FixedBytes(add_bytes) => // etc,
            Self::Percent(f) => // etc,
        }
    }
}

My bad. I didn't see heed/env.rs using fixed_bytes(). Why not replace:

Yeah that could work too.

hinto-janai avatar Apr 30 '24 16:04 hinto-janai

@SyntheticBird45 is this this still something you want, IMO these are ok being pub

Boog900 avatar Jun 14 '24 17:06 Boog900

lmao nah no need to resolve conflict for that

SyntheticBird45 avatar Jun 14 '24 17:06 SyntheticBird45