• 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

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

3
use deno_core::anyhow::anyhow;
4
use deno_core::anyhow::Result;
5
use deno_core::op2;
6

7
#[op2(fast)]
1,159✔
8
pub fn op_is_ascii(#[buffer] buf: &[u8]) -> bool {
×
UNCOV
9
  buf.is_ascii()
×
10
}
×
11

12
#[op2(fast)]
1,159✔
13
pub fn op_is_utf8(#[buffer] buf: &[u8]) -> bool {
×
UNCOV
14
  std::str::from_utf8(buf).is_ok()
×
UNCOV
15
}
×
16

17
#[op2]
1,159✔
18
#[buffer]
UNCOV
19
pub fn op_transcode(
×
UNCOV
20
  #[buffer] source: &[u8],
×
UNCOV
21
  #[string] from_encoding: &str,
×
UNCOV
22
  #[string] to_encoding: &str,
×
UNCOV
23
) -> Result<Vec<u8>> {
×
UNCOV
24
  match (from_encoding, to_encoding) {
×
UNCOV
25
    ("utf8", "ascii") => Ok(utf8_to_ascii(source)),
×
UNCOV
26
    ("utf8", "latin1") => Ok(utf8_to_latin1(source)),
×
UNCOV
27
    ("utf8", "utf16le") => utf8_to_utf16le(source),
×
UNCOV
28
    ("utf16le", "utf8") => utf16le_to_utf8(source),
×
UNCOV
29
    ("latin1", "utf16le") | ("ascii", "utf16le") => {
×
UNCOV
30
      Ok(latin1_ascii_to_utf16le(source))
×
31
    }
UNCOV
32
    (from, to) => Err(anyhow!("Unable to transcode Buffer {from}->{to}")),
×
33
  }
UNCOV
34
}
×
35

UNCOV
36
fn latin1_ascii_to_utf16le(source: &[u8]) -> Vec<u8> {
×
UNCOV
37
  let mut result = Vec::with_capacity(source.len() * 2);
×
UNCOV
38
  for &byte in source {
×
UNCOV
39
    result.push(byte);
×
UNCOV
40
    result.push(0);
×
UNCOV
41
  }
×
UNCOV
42
  result
×
UNCOV
43
}
×
44

UNCOV
45
fn utf16le_to_utf8(source: &[u8]) -> Result<Vec<u8>> {
×
UNCOV
46
  let ucs2_vec: Vec<u16> = source
×
UNCOV
47
    .chunks(2)
×
UNCOV
48
    .map(|chunk| u16::from_le_bytes([chunk[0], chunk[1]]))
×
UNCOV
49
    .collect();
×
UNCOV
50
  String::from_utf16(&ucs2_vec)
×
UNCOV
51
    .map(|utf8_string| utf8_string.into_bytes())
×
UNCOV
52
    .map_err(|e| anyhow!("Invalid UTF-16 sequence: {}", e))
×
UNCOV
53
}
×
54

UNCOV
55
fn utf8_to_utf16le(source: &[u8]) -> Result<Vec<u8>> {
×
UNCOV
56
  let utf8_string = std::str::from_utf8(source)?;
×
UNCOV
57
  let ucs2_vec: Vec<u16> = utf8_string.encode_utf16().collect();
×
UNCOV
58
  let bytes: Vec<u8> = ucs2_vec.iter().flat_map(|&x| x.to_le_bytes()).collect();
×
UNCOV
59
  Ok(bytes)
×
UNCOV
60
}
×
61

UNCOV
62
fn utf8_to_latin1(source: &[u8]) -> Vec<u8> {
×
UNCOV
63
  let mut latin1_bytes = Vec::with_capacity(source.len());
×
UNCOV
64
  let mut i = 0;
×
UNCOV
65
  while i < source.len() {
×
UNCOV
66
    match source[i] {
×
UNCOV
67
      byte if byte <= 0x7F => {
×
UNCOV
68
        // ASCII character
×
UNCOV
69
        latin1_bytes.push(byte);
×
UNCOV
70
        i += 1;
×
UNCOV
71
      }
×
UNCOV
72
      byte if (0xC2..=0xDF).contains(&byte) && i + 1 < source.len() => {
×
UNCOV
73
        // 2-byte UTF-8 sequence
×
UNCOV
74
        let codepoint =
×
UNCOV
75
          ((byte as u16 & 0x1F) << 6) | (source[i + 1] as u16 & 0x3F);
×
UNCOV
76
        latin1_bytes.push(if codepoint <= 0xFF {
×
UNCOV
77
          codepoint as u8
×
78
        } else {
UNCOV
79
          b'?'
×
80
        });
UNCOV
81
        i += 2;
×
82
      }
83
      _ => {
84
        // 3-byte or 4-byte UTF-8 sequence, or invalid UTF-8
UNCOV
85
        latin1_bytes.push(b'?');
×
UNCOV
86
        // Skip to the next valid UTF-8 start byte
×
UNCOV
87
        i += 1;
×
UNCOV
88
        while i < source.len() && (source[i] & 0xC0) == 0x80 {
×
UNCOV
89
          i += 1;
×
UNCOV
90
        }
×
91
      }
92
    }
93
  }
UNCOV
94
  latin1_bytes
×
UNCOV
95
}
×
96

UNCOV
97
fn utf8_to_ascii(source: &[u8]) -> Vec<u8> {
×
UNCOV
98
  let mut ascii_bytes = Vec::with_capacity(source.len());
×
UNCOV
99
  let mut i = 0;
×
UNCOV
100
  while i < source.len() {
×
UNCOV
101
    match source[i] {
×
UNCOV
102
      byte if byte <= 0x7F => {
×
UNCOV
103
        // ASCII character
×
UNCOV
104
        ascii_bytes.push(byte);
×
UNCOV
105
        i += 1;
×
UNCOV
106
      }
×
107
      _ => {
108
        // Non-ASCII character
UNCOV
109
        ascii_bytes.push(b'?');
×
UNCOV
110
        // Skip to the next valid UTF-8 start byte
×
UNCOV
111
        i += 1;
×
UNCOV
112
        while i < source.len() && (source[i] & 0xC0) == 0x80 {
×
UNCOV
113
          i += 1;
×
UNCOV
114
        }
×
115
      }
116
    }
117
  }
UNCOV
118
  ascii_bytes
×
UNCOV
119
}
×
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