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

supabase / edge-runtime / 17229631411

26 Aug 2025 06:13AM UTC coverage: 51.84% (-2.1%) from 53.937%
17229631411

push

github

web-flow
fix: remove another bottleneck that causes boot time spike (#596)

* fix: remove another bottleneck that causes boot time spike

* chore: add integration test

28 of 33 new or added lines in 1 file covered. (84.85%)

4922 existing lines in 74 files now uncovered.

18444 of 35579 relevant lines covered (51.84%)

5545.51 hits per line

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

60.0
/ext/node/ops/zlib/alloc.rs
1
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2

3
// Workaround for https://github.com/rust-lang/libz-sys/issues/55
4
// See https://github.com/rust-lang/flate2-rs/blob/31fb07820345691352aaa64f367c1e482ad9cfdc/src/ffi/c.rs#L60
5
use std::alloc::Layout;
6
use std::alloc::{self};
7
use std::os::raw::c_void;
8
use std::ptr;
9

10
const ALIGN: usize = std::mem::align_of::<usize>();
11

12
fn align_up(size: usize, align: usize) -> usize {
8✔
13
  (size + align - 1) & !(align - 1)
8✔
14
}
8✔
15

16
pub extern "C" fn zalloc(
8✔
17
  _ptr: *mut c_void,
8✔
18
  items: u32,
8✔
19
  item_size: u32,
8✔
20
) -> *mut c_void {
8✔
21
  // We need to multiply `items` and `item_size` to get the actual desired
22
  // allocation size. Since `zfree` doesn't receive a size argument we
23
  // also need to allocate space for a `usize` as a header so we can store
24
  // how large the allocation is to deallocate later.
25
  let size = match (items as usize)
8✔
26
    .checked_mul(item_size as usize)
8✔
27
    .map(|size| align_up(size, ALIGN))
8✔
28
    .and_then(|i| i.checked_add(std::mem::size_of::<usize>()))
8✔
29
  {
30
    Some(i) => i,
8✔
UNCOV
31
    None => return ptr::null_mut(),
×
32
  };
33

34
  // Make sure the `size` isn't too big to fail `Layout`'s restrictions
35
  let layout = match Layout::from_size_align(size, ALIGN) {
8✔
36
    Ok(layout) => layout,
8✔
UNCOV
37
    Err(_) => return ptr::null_mut(),
×
38
  };
39

40
  // SAFETY: `layout` has non-zero size, guaranteed to be a sentinel address
41
  // or a null pointer.
42
  unsafe {
43
    // Allocate the data, and if successful store the size we allocated
44
    // at the beginning and then return an offset pointer.
45
    let ptr = alloc::alloc(layout) as *mut usize;
8✔
46
    if ptr.is_null() {
8✔
UNCOV
47
      return ptr as *mut c_void;
×
48
    }
8✔
49
    *ptr = size;
8✔
50
    ptr.add(1) as *mut c_void
8✔
51
  }
52
}
8✔
53

54
pub extern "C" fn zfree(_ptr: *mut c_void, address: *mut c_void) {
×
55
  // SAFETY: Move our address being free'd back one pointer, read the size we
×
56
  // stored in `zalloc`, and then free it using the standard Rust
×
57
  // allocator.
×
58
  unsafe {
×
59
    let ptr = (address as *mut usize).offset(-1);
×
60
    let size = *ptr;
×
UNCOV
61
    let layout = Layout::from_size_align_unchecked(size, ALIGN);
×
UNCOV
62
    alloc::dealloc(ptr as *mut u8, layout)
×
UNCOV
63
  }
×
UNCOV
64
}
×
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