From a94c1556cecc70ea4c543f3e783bbd01a06e711e Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 19 Sep 2019 05:22:24 +0300 Subject: [PATCH] array: remove temporary repeat2() --- compiler/fn.v | 2 +- compiler/token.v | 2 +- vlib/builtin/array.v | 15 --------------- vlib/builtin/int.v | 2 +- vlib/builtin/js/array.v | 2 +- vlib/builtin/js/int.v | 2 +- vlib/builtin/map.v | 2 +- vlib/builtin/string.v | 4 ++-- vlib/strings/similarity.v | 4 ++-- vlib/strings/strings.v | 2 +- 10 files changed, 11 insertions(+), 26 deletions(-) diff --git a/compiler/fn.v b/compiler/fn.v index 676b4d8366..981e467db2 100644 --- a/compiler/fn.v +++ b/compiler/fn.v @@ -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 } } diff --git a/compiler/token.v b/compiler/token.v index 5a1e2b5ac8..4ff1cd0551 100644 --- a/compiler/token.v +++ b/compiler/token.v @@ -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' diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index ac06e15a4f..c5be550af9 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -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) } diff --git a/vlib/builtin/int.v b/vlib/builtin/int.v index d6d7a97cb7..de20dae328 100644 --- a/vlib/builtin/int.v +++ b/vlib/builtin/int.v @@ -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] } diff --git a/vlib/builtin/js/array.v b/vlib/builtin/js/array.v index e8235332c0..53fc7582d4 100644 --- a/vlib/builtin/js/array.v +++ b/vlib/builtin/js/array.v @@ -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 } diff --git a/vlib/builtin/js/int.v b/vlib/builtin/js/int.v index cb926ee180..a8c6284439 100644 --- a/vlib/builtin/js/int.v +++ b/vlib/builtin/js/int.v @@ -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] } diff --git a/vlib/builtin/map.v b/vlib/builtin/map.v index c84a5b2832..267880916c 100644 --- a/vlib/builtin/map.v +++ b/vlib/builtin/map.v @@ -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 } diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index ac715a4561..6a8f45dfc9 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -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 } diff --git a/vlib/strings/similarity.v b/vlib/strings/similarity.v index 7ae64fa35c..d3dbb6454f 100644 --- a/vlib/strings/similarity.v +++ b/vlib/strings/similarity.v @@ -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++ diff --git a/vlib/strings/strings.v b/vlib/strings/strings.v index f7180ab493..76c3b3f0cc 100644 --- a/vlib/strings/strings.v +++ b/vlib/strings/strings.v @@ -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 }