mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
array: remove temporary repeat2()
This commit is contained in:
parent
cb31eeec55
commit
a94c1556ce
@ -132,7 +132,7 @@ fn (p mut Parser) is_sig() bool {
|
||||
fn new_fn(mod string, is_public bool) Fn {
|
||||
return Fn {
|
||||
mod: mod
|
||||
local_vars: [Var{}].repeat2(MaxLocalVars)
|
||||
local_vars: [Var{}].repeat(MaxLocalVars)
|
||||
is_public: is_public
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ fn build_keys() map[string]int {
|
||||
|
||||
// TODO remove once we have `enum Token { name('name') if('if') ... }`
|
||||
fn build_token_str() []string {
|
||||
mut s := [''].repeat2(NrTokens)
|
||||
mut s := [''].repeat(NrTokens)
|
||||
s[Token.keyword_beg] = ''
|
||||
s[Token.keyword_end] = ''
|
||||
s[Token.eof] = 'eof'
|
||||
|
@ -86,21 +86,6 @@ pub fn (a array) repeat(nr_repeats int) array {
|
||||
return arr
|
||||
}
|
||||
|
||||
// TODO remove
|
||||
pub fn (a array) repeat2(nr_repeats int) array {
|
||||
arr := array {
|
||||
len: nr_repeats
|
||||
cap: nr_repeats
|
||||
element_size: a.element_size
|
||||
data: malloc(nr_repeats * a.element_size)
|
||||
}
|
||||
val := a.data + 0 //nr_repeats * a.element_size
|
||||
for i := 0; i < nr_repeats; i++ {
|
||||
C.memcpy(arr.data + i * a.element_size, val, a.element_size)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
pub fn (a mut array) sort_with_compare(compare voidptr) {
|
||||
C.qsort(a.data, a.len, a.element_size, compare)
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ pub fn (c byte) is_capital() bool {
|
||||
}
|
||||
|
||||
pub fn (b []byte) clone() []byte {
|
||||
mut res := [byte(0)].repeat2(b.len)
|
||||
mut res := [byte(0)].repeat(b.len)
|
||||
for i := 0; i < b.len; i++ {
|
||||
res[i] = b[i]
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ fn array_repeat(val voidptr, nr_repeats, elm_size int) array {
|
||||
return val
|
||||
}
|
||||
|
||||
pub fn (a array) repeat2(nr_repeats int) array {
|
||||
pub fn (a array) repeat(nr_repeats int) array {
|
||||
#return Array(a[0]).fill(nr_repeats)
|
||||
return a
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ pub fn (c byte) is_capital() bool {
|
||||
}
|
||||
|
||||
pub fn (b []byte) clone() []byte {
|
||||
mut res := [byte(0)].repeat2(b.len)
|
||||
mut res := [byte(0)].repeat(b.len)
|
||||
for i := 0; i < b.len; i++ {
|
||||
res[i] = b[i]
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ fn preorder_keys(node &mapnode, keys mut []string, key_i int) int {
|
||||
}
|
||||
|
||||
pub fn (m mut map) keys() []string {
|
||||
mut keys := [''].repeat2(m.size)
|
||||
mut keys := [''].repeat(m.size)
|
||||
if isnil(m.root) {
|
||||
return keys
|
||||
}
|
||||
|
@ -380,7 +380,7 @@ pub fn (s string) index(p string) int {
|
||||
if p.len > s.len {
|
||||
return -1
|
||||
}
|
||||
mut prefix := [0].repeat2(p.len)
|
||||
mut prefix := [0].repeat(p.len)
|
||||
mut j := 0
|
||||
for i := 1; i < p.len; i++ {
|
||||
for p[j] != p[i] && j > 0 {
|
||||
@ -898,7 +898,7 @@ pub fn (s string) bytes() []byte {
|
||||
if s.len == 0 {
|
||||
return []byte
|
||||
}
|
||||
mut buf := [byte(0)].repeat2(s.len)
|
||||
mut buf := [byte(0)].repeat(s.len)
|
||||
C.memcpy(buf.data, s.str, s.len)
|
||||
return buf
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ module strings
|
||||
// use levenshtein distance algorithm to calculate
|
||||
// the distance between between two strings (lower is closer)
|
||||
pub fn levenshtein_distance(a, b string) int {
|
||||
mut f := [0].repeat2(b.len+1)
|
||||
mut f := [0].repeat(b.len+1)
|
||||
for ca in a {
|
||||
mut j := 1
|
||||
mut fj1 := f[0]
|
||||
|
@ -5,7 +5,7 @@ pub fn repeat(c byte, n int) string {
|
||||
return ''
|
||||
}
|
||||
//mut arr := malloc(n + 1)
|
||||
mut arr := [byte(0)].repeat2(n + 1)
|
||||
mut arr := [byte(0)].repeat(n + 1)
|
||||
for i := 0; i < n; i++ {
|
||||
arr[i] = c
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user