refactor: switch StringBuilder capacity to size_hint
check / check (macos-latest) (push) Failing after 2m16s
check / check (ubuntu-latest) (push) Failing after 2m14s
check / check (windows-latest) (push) Failing after 14m21s

- Replace the StringBuilder(capacity=...) argument with size_hint=... in base32, base64, hex, SAM quoting/parsing.
- Drop trailing commas after the last field in I2NP, NTCP2 and tunnel fragment enum variants (formatter cleanup).
- No behavior change; encoded output and parsed fields are unchanged.
This commit is contained in:
nandi committed 2026-11-27 16:57:28 -08:00
1 parent cadb8cd898
commit 274bb319ab
7 files changed
+12 -12

No files matched your search

+1 -1
View File
@@ -24,7 +24,7 @@ pub fn base32_encode(data : Bytes) -> String {
if len == 0 { if len == 0 {
return "" return ""
} }
let buf = StringBuilder(capacity=(len * 8 + 4) / 5) let buf = StringBuilder(size_hint=(len * 8 + 4) / 5)
let mut buffer = 0 let mut buffer = 0
let mut bits_left = 0 let mut bits_left = 0
for i = 0; i < len; i = i + 1 { for i = 0; i < len; i = i + 1 {
+1 -1
View File
@@ -28,7 +28,7 @@ pub fn base64_encode(data : Bytes) -> String {
if len == 0 { if len == 0 {
return "" return ""
} }
let buf = StringBuilder(capacity=(len + 2) / 3 * 4) let buf = StringBuilder(size_hint=(len + 2) / 3 * 4)
let mut i = 0 let mut i = 0
while i < len { while i < len {
let b0 = data[i].to_int() let b0 = data[i].to_int()
+1 -1
View File
@@ -279,7 +279,7 @@ let hex_digits : Bytes = b"0123456789abcdef"
///| ///|
/// Encodes `Bytes` as lowercase hexadecimal. /// Encodes `Bytes` as lowercase hexadecimal.
pub fn hex_encode(data : Bytes) -> String { pub fn hex_encode(data : Bytes) -> String {
let buf = StringBuilder(capacity=data.length() * 2) let buf = StringBuilder(size_hint=data.length() * 2)
for i = 0; i < data.length(); i = i + 1 { for i = 0; i < data.length(); i = i + 1 {
let b = data[i].to_int() let b = data[i].to_int()
buf.write_char(hex_digits[b >> 4].to_int().unsafe_to_char()) buf.write_char(hex_digits[b >> 4].to_int().unsafe_to_char())
+4 -4
View File
@@ -158,7 +158,7 @@ pub(all) enum I2npPayload {
reply_token~ : UInt32, reply_token~ : UInt32,
reply_tunnel_id~ : UInt32, reply_tunnel_id~ : UInt32,
reply_gateway~ : @common.Hash?, reply_gateway~ : @common.Hash?,
data~ : Bytes, data~ : Bytes
) )
/// Type 2: DatabaseLookup (queries NetDB for a key). /// Type 2: DatabaseLookup (queries NetDB for a key).
DatabaseLookup( DatabaseLookup(
@@ -166,13 +166,13 @@ pub(all) enum I2npPayload {
from~ : @common.Hash, from~ : @common.Hash,
flags~ : Byte, flags~ : Byte,
reply_tunnel_id~ : UInt32?, reply_tunnel_id~ : UInt32?,
excluded_peers~ : Array[@common.Hash], excluded_peers~ : Array[@common.Hash]
) )
/// Type 3: DatabaseSearchReply (floodfill returns closest router hashes). /// Type 3: DatabaseSearchReply (floodfill returns closest router hashes).
DatabaseSearchReply( DatabaseSearchReply(
key~ : @common.Hash, key~ : @common.Hash,
peer_hashes~ : Array[@common.Hash], peer_hashes~ : Array[@common.Hash],
from~ : @common.Hash, from~ : @common.Hash
) )
/// Type 10: DeliveryStatus (confirms delivery of a message or tunnel test). /// Type 10: DeliveryStatus (confirms delivery of a message or tunnel test).
DeliveryStatus(msg_id~ : UInt32, timestamp_ms~ : UInt64) DeliveryStatus(msg_id~ : UInt32, timestamp_ms~ : UInt64)
@@ -219,7 +219,7 @@ pub fn I2npPayload::encode_body(self : I2npPayload) -> Bytes raise I2npError {
reply_token~, reply_token~,
reply_tunnel_id~, reply_tunnel_id~,
reply_gateway~, reply_gateway~,
data~, data~
) => { ) => {
key.encode(w) key.encode(w)
w.write_u8(store_type) w.write_u8(store_type)
+1 -1
View File
@@ -28,7 +28,7 @@ pub(all) enum Ntcp2Block {
Termination( Termination(
valid_frames_received~ : UInt64, valid_frames_received~ : UInt64,
reason~ : Byte, reason~ : Byte,
additional_data~ : Bytes, additional_data~ : Bytes
) )
/// Type 254: Padding (must be last block in frame). /// Type 254: Padding (must be last block in frame).
Padding(Bytes) Padding(Bytes)
+3 -3
View File
@@ -69,7 +69,7 @@ fn quote_value(s : String) -> String {
if !needs_quoting(s) { if !needs_quoting(s) {
return s return s
} }
let buf = StringBuilder(capacity=s.length() + 2) let buf = StringBuilder(size_hint=s.length() + 2)
buf.write_char('"') buf.write_char('"')
for ch in s { for ch in s {
if ch == '"' || ch == '\\' { if ch == '"' || ch == '\\' {
@@ -175,11 +175,11 @@ fn split_kv(token : String) -> (String, String)? {
if eq_idx <= 0 { if eq_idx <= 0 {
return None return None
} }
let kbuf = StringBuilder(capacity=eq_idx) let kbuf = StringBuilder(size_hint=eq_idx)
for i = 0; i < eq_idx; i = i + 1 { for i = 0; i < eq_idx; i = i + 1 {
kbuf.write_char(chars[i]) kbuf.write_char(chars[i])
} }
let vbuf = StringBuilder(capacity=chars.length() - eq_idx - 1) let vbuf = StringBuilder(size_hint=chars.length() - eq_idx - 1)
for i = eq_idx + 1; i < chars.length(); i = i + 1 { for i = eq_idx + 1; i < chars.length(); i = i + 1 {
vbuf.write_char(chars[i]) vbuf.write_char(chars[i])
} }
+1 -1
View File
@@ -75,7 +75,7 @@ pub(all) enum TunnelFragment {
target~ : DeliveryTarget, target~ : DeliveryTarget,
fragmented~ : Bool, fragmented~ : Bool,
msg_id~ : UInt32, msg_id~ : UInt32,
data~ : Bytes, data~ : Bytes
) )
FollowOn(frag_num~ : Int32, is_last~ : Bool, msg_id~ : UInt32, data~ : Bytes) FollowOn(frag_num~ : Int32, is_last~ : Bool, msg_id~ : UInt32, data~ : Bytes)
} }