mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
builtin: remove unsafe{} blocks from data_to_hex_string/2
This commit is contained in:
parent
c5e8ad19df
commit
a64dfc776b
1 changed files with 5 additions and 9 deletions
|
@ -2868,20 +2868,16 @@ pub fn (s string) hex() string {
|
||||||
|
|
||||||
@[unsafe]
|
@[unsafe]
|
||||||
fn data_to_hex_string(data &u8, len int) string {
|
fn data_to_hex_string(data &u8, len int) string {
|
||||||
mut hex := unsafe { malloc_noscan(u64(len) * 2 + 1) }
|
mut hex := malloc_noscan(u64(len) * 2 + 1)
|
||||||
mut dst := 0
|
mut dst := 0
|
||||||
for c in 0 .. len {
|
for c in 0 .. len {
|
||||||
b := data[c]
|
b := data[c]
|
||||||
n0 := b >> 4
|
n0 := b >> 4
|
||||||
n1 := b & 0xF
|
n1 := b & 0xF
|
||||||
unsafe {
|
hex[dst] = if n0 < 10 { n0 + `0` } else { n0 + `W` }
|
||||||
hex[dst] = if n0 < 10 { n0 + `0` } else { n0 + `W` }
|
hex[dst + 1] = if n1 < 10 { n1 + `0` } else { n1 + `W` }
|
||||||
hex[dst + 1] = if n1 < 10 { n1 + `0` } else { n1 + `W` }
|
|
||||||
}
|
|
||||||
dst += 2
|
dst += 2
|
||||||
}
|
}
|
||||||
unsafe {
|
hex[dst] = 0
|
||||||
hex[dst] = 0
|
return tos(hex, dst)
|
||||||
return tos(hex, dst)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue