mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: unsafe vlib pointer indexing (#5836)
This commit is contained in:
@ -5,10 +5,11 @@ pub fn repeat(c byte, n int) string {
|
||||
if n <= 0 {
|
||||
return ''
|
||||
}
|
||||
mut bytes := &byte(0)
|
||||
unsafe { bytes = malloc(n + 1) }
|
||||
C.memset( bytes, c, n )
|
||||
bytes[n] = `0`
|
||||
mut bytes := unsafe {malloc(n + 1)}
|
||||
unsafe {
|
||||
C.memset( bytes, c, n )
|
||||
bytes[n] = `0`
|
||||
}
|
||||
return string( bytes, n )
|
||||
}
|
||||
|
||||
@ -21,14 +22,17 @@ pub fn repeat_string(s string, n int) string {
|
||||
}
|
||||
slen := s.len
|
||||
blen := slen*n
|
||||
mut bytes := &byte(0)
|
||||
unsafe { bytes = malloc(blen + 1) }
|
||||
mut bytes := unsafe {malloc(blen + 1)}
|
||||
for bi in 0..n {
|
||||
bislen := bi*slen
|
||||
for si in 0..slen {
|
||||
bytes[bislen+si] = s[si]
|
||||
unsafe {
|
||||
bytes[bislen+si] = s[si]
|
||||
}
|
||||
}
|
||||
}
|
||||
bytes[blen] = `0`
|
||||
unsafe {
|
||||
bytes[blen] = `0`
|
||||
}
|
||||
return string( bytes, blen )
|
||||
}
|
||||
|
Reference in New Issue
Block a user