refactor: switch StringBuilder capacity to size_hint
- 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:
1 parent
cadb8cd898
commit
274bb319ab
7 files changed
+12
-12
No files matched your search
+1
-1
@@ -24,7 +24,7 @@ pub fn base32_encode(data : Bytes) -> String {
|
||||
if len == 0 {
|
||||
return ""
|
||||
}
|
||||
let buf = StringBuilder(capacity=(len * 8 + 4) / 5)
|
||||
let buf = StringBuilder(size_hint=(len * 8 + 4) / 5)
|
||||
let mut buffer = 0
|
||||
let mut bits_left = 0
|
||||
for i = 0; i < len; i = i + 1 {
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ pub fn base64_encode(data : Bytes) -> String {
|
||||
if len == 0 {
|
||||
return ""
|
||||
}
|
||||
let buf = StringBuilder(capacity=(len + 2) / 3 * 4)
|
||||
let buf = StringBuilder(size_hint=(len + 2) / 3 * 4)
|
||||
let mut i = 0
|
||||
while i < len {
|
||||
let b0 = data[i].to_int()
|
||||
|
||||
+1
-1
@@ -279,7 +279,7 @@ let hex_digits : Bytes = b"0123456789abcdef"
|
||||
///|
|
||||
/// Encodes `Bytes` as lowercase hexadecimal.
|
||||
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 {
|
||||
let b = data[i].to_int()
|
||||
buf.write_char(hex_digits[b >> 4].to_int().unsafe_to_char())
|
||||
|
||||
Reference in new issue
Block a user