Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crypto/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ pub impl ByteSource for Bytes
pub impl ByteSource for BytesView

pub(open) trait CryptoHasher {
size(Self) -> Int
block_size(Self) -> Int
reset(Self) -> Unit
update(Self, BytesView) -> Unit
finalize_into(Self, FixedArray[Byte], offset~ : Int) -> Unit
fn size(Self) -> Int
fn block_size(Self) -> Int
fn reset(Self) -> Unit
fn update(Self, BytesView) -> Unit
fn finalize_into(Self, FixedArray[Byte], offset~ : Int) -> Unit
}

25 changes: 22 additions & 3 deletions encoding/encoding.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,28 @@ pub fn encode(encoding : Encoding, src : String) -> Bytes {
UTF16BE => write_utf16be_char
_ => abort("unreachable")
}
for char in src {
// SAFETY: Assume String are always valid UTF16LE
write(new_buf, char)
// Walk by UTF-16 code unit and assemble surrogate pairs inline. This
// avoids `for char in src`, which goes through String::iter +
// Iter::next per char (~30% of self time on an ASCII-heavy 64 KiB
// bench even though the inner body is small).
let len = src.length()
let mut i = 0
while i < len {
let cu = src.unsafe_get(i).to_int()
i += 1
let cp = if cu >= 0xD800 && cu <= 0xDBFF && i < len {
let cu2 = src.unsafe_get(i).to_int()
if cu2 >= 0xDC00 && cu2 <= 0xDFFF {
i += 1
(cu - 0xD800) * 0x400 + (cu2 - 0xDC00) + 0x10000
} else {
cu
}
} else {
cu
}
// SAFETY: Assume String contains valid UTF-16
write(new_buf, cp.unsafe_to_char())
}
new_buf.to_bytes()
}
Expand Down
16 changes: 8 additions & 8 deletions num/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ package "moonbitlang/x/num"
// Traits
#deprecated
pub trait Num {
from_int(Int) -> Self
op_add(Self, Self) -> Self
op_sub(Self, Self) -> Self
op_mul(Self, Self) -> Self
op_div(Self, Self) -> Self
op_neg(Self) -> Self
abs(Self) -> Self
signum(Self) -> Self
fn from_int(Int) -> Self
fn op_add(Self, Self) -> Self
fn op_sub(Self, Self) -> Self
fn op_mul(Self, Self) -> Self
fn op_div(Self, Self) -> Self
fn op_neg(Self) -> Self
fn abs(Self) -> Self
fn signum(Self) -> Self
}

Loading