1
0
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:
Alexander Medvednikov 2019-09-19 05:22:24 +03:00
parent cb31eeec55
commit a94c1556ce
10 changed files with 11 additions and 26 deletions

View File

@ -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
}
}

View File

@ -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'

View File

@ -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)
}

View File

@ -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]
}

View File

@ -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
}

View File

@ -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]
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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]
@ -50,7 +50,7 @@ pub fn dice_coefficient(s1, s2 string) f32 {
mut intersection_size := 0
for i := 0; i < b.len-1; i++ {
bigram := b.substr(i, i+2)
count := if bigram in first_bigrams { first_bigrams[bigram] } else { 0 }
count := if bigram in first_bigrams { first_bigrams[bigram] } else { 0 }
if count > 0 {
first_bigrams[bigram] = count - 1
intersection_size++

View File

@ -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
}