diff --git a/vlib/bitfield/bitfield.v b/vlib/bitfield/bitfield.v index e7ae271145..1066b019a3 100644 --- a/vlib/bitfield/bitfield.v +++ b/vlib/bitfield/bitfield.v @@ -68,7 +68,7 @@ pub fn new(size int) BitField { output := BitField{ size: size //field: *u32(calloc(bitnslots(size) * slot_size / 8)) - field: [u32(0)].repeat(bitnslots(size)) + field: []u32{len:bitnslots(size)} } return output } @@ -394,7 +394,7 @@ pub fn (mut instance BitField) resize(new_size int) { new_bitnslots := bitnslots(new_size) old_size := instance.size old_bitnslots := bitnslots(old_size) - mut field := [u32(0)].repeat(new_bitnslots) + mut field := []u32{len:new_bitnslots} for i := 0; i < old_bitnslots && i < new_bitnslots; i++ { field[i] = instance.field[i] } diff --git a/vlib/bitfield/bitfield_test.v b/vlib/bitfield/bitfield_test.v index 8e486436b5..6b305758a6 100644 --- a/vlib/bitfield/bitfield_test.v +++ b/vlib/bitfield/bitfield_test.v @@ -1,7 +1,6 @@ import bitfield import rand -import time fn test_bf_new_size() { instance := bitfield.new(75) diff --git a/vlib/builtin/bare/.checks/forkedtest/forkedtest.v b/vlib/builtin/bare/.checks/forkedtest/forkedtest.v index 9f3f7aacd0..6d9272c7ec 100644 --- a/vlib/builtin/bare/.checks/forkedtest/forkedtest.v +++ b/vlib/builtin/bare/.checks/forkedtest/forkedtest.v @@ -7,7 +7,7 @@ pub fn run (op fn(), label string, code Wi_si_code, status int) int { sys_exit(0) } - siginfo := [0].repeat(int(Sig_index.si_size)) + siginfo := []int{len:int(Sig_index.si_size)} e := sys_waitid(.p_pid, child, intptr(&siginfo[0]), .wexited, 0) diff --git a/vlib/builtin/bare/.checks/linuxsys/linuxsys.v b/vlib/builtin/bare/.checks/linuxsys/linuxsys.v index a8625d9da7..cca5cb62fd 100644 --- a/vlib/builtin/bare/.checks/linuxsys/linuxsys.v +++ b/vlib/builtin/bare/.checks/linuxsys/linuxsys.v @@ -40,7 +40,7 @@ fn check_read_write_pipe() { // sys_read // sys_close // - buffer0 := [byte(0)].repeat(128) + buffer0 := []byte{len:(128)} buffer := byteptr(buffer0.data) fd := [-1, -1] @@ -87,7 +87,7 @@ fn check_read_file() { sys_close sys_open */ - buffer0 := [byte(0)].repeat(128) + buffer0 := []byte{len:(128)} buffer := byteptr(buffer0.data) test_file := "sample_text1.txt" diff --git a/vlib/builtin/bare/.checks/string/string.v b/vlib/builtin/bare/.checks/string/string.v index 864d201b39..54c06e7eff 100644 --- a/vlib/builtin/bare/.checks/string/string.v +++ b/vlib/builtin/bare/.checks/string/string.v @@ -8,7 +8,7 @@ fn check_string_eq () { } fn check_i64_tos() { - buffer0 := [byte(0)].repeat(128) + buffer0 := []byte{len:(128)} buffer := byteptr(buffer0.data) s0 := i64_tos(buffer, 70, 140, 10) diff --git a/vlib/builtin/int.v b/vlib/builtin/int.v index 718f47de03..250dbb3c65 100644 --- a/vlib/builtin/int.v +++ b/vlib/builtin/int.v @@ -399,7 +399,7 @@ pub fn (c byte) is_capital() bool { } pub fn (b []byte) clone() []byte { - mut res := [byte(0)].repeat(b.len) + mut res := []byte{len: b.len} //mut res := make([]byte, {repeat:b.len}) for i in 0..b.len { res[i] = b[i] diff --git a/vlib/builtin/sorted_map.v b/vlib/builtin/sorted_map.v index 5e96466807..518649d30c 100644 --- a/vlib/builtin/sorted_map.v +++ b/vlib/builtin/sorted_map.v @@ -379,7 +379,7 @@ fn (n &mapnode) subkeys(mut keys []string, at int) int { } pub fn (m &SortedMap) keys() []string { - mut keys := [''].repeat(m.len) + mut keys := []string{len:m.len} if isnil(m.root) || m.root.len == 0 { return keys } diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index bd28c01503..3f9681e602 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -595,7 +595,7 @@ fn (s string) index_kmp(p string) int { if p.len > s.len { return -1 } - mut prefix := [0].repeat(p.len) + mut prefix := []int{len:p.len} mut j := 0 for i := 1; i < p.len; i++ { for p.str[j] != p.str[i] && j > 0 { @@ -1326,7 +1326,7 @@ pub fn (s string) bytes() []byte { if s.len == 0 { return [] } - mut buf := [byte(0)].repeat(s.len) + mut buf := []byte{ len:s.len } C.memcpy(buf.data, s.str, s.len) return buf } diff --git a/vlib/crypto/aes/aes_cbc.v b/vlib/crypto/aes/aes_cbc.v index 9694bc7c87..2623172dce 100644 --- a/vlib/crypto/aes/aes_cbc.v +++ b/vlib/crypto/aes/aes_cbc.v @@ -30,7 +30,7 @@ fn new_aes_cbc(b AesCipher, iv []byte) AesCbc { b: b, block_size: b.block_size(), iv: iv.clone(), - tmp: [byte(0)].repeat(b.block_size()), + tmp: []byte{len:(b.block_size()),} } } diff --git a/vlib/crypto/aes/cypher_generic.v b/vlib/crypto/aes/cypher_generic.v index bd7f3b593d..724334d80a 100644 --- a/vlib/crypto/aes/cypher_generic.v +++ b/vlib/crypto/aes/cypher_generic.v @@ -9,8 +9,8 @@ module aes fn new_cipher_generic(key []byte) AesCipher { n := key.len + 28 mut c := AesCipher{ - enc: [u32(0)].repeat(n) - dec: [u32(0)].repeat(n) + enc: []u32{len:(n)} + dec: []u32{len:(n)} } expand_key_generic(key, mut c.enc, mut c.dec) return c diff --git a/vlib/crypto/md5/md5.v b/vlib/crypto/md5/md5.v index d822175200..1f48adff9e 100644 --- a/vlib/crypto/md5/md5.v +++ b/vlib/crypto/md5/md5.v @@ -38,8 +38,8 @@ mut: } fn (mut d Digest) reset() { - d.s = [u32(0)].repeat(4) - d.x = [byte(0)].repeat(block_size) + d.s = []u32{len:(4)} + d.x = []byte{len:(block_size)} d.s[0] = u32(init0) d.s[1] = u32(init1) d.s[2] = u32(init2) @@ -105,7 +105,7 @@ pub fn (mut d Digest) checksum() []byte { // // 1 byte end marker :: 0-63 padding bytes :: 8 byte length // tmp := [1 + 63 + 8]byte{0x80} - mut tmp := [byte(0)].repeat(1 + 63 + 8) + mut tmp := []byte{len:(1 + 63 + 8)} tmp[0] = 0x80 pad := ((55 - d.len) % 64) // calculate number of padding bytes binary.little_endian_put_u64(mut tmp[1+pad..], d.len<<3) // append length in bits @@ -117,7 +117,7 @@ pub fn (mut d Digest) checksum() []byte { panic('d.nx != 0') } - digest := [byte(0)].repeat(size) + digest := []byte{len:(size)} binary.little_endian_put_u32(mut digest, d.s[0]) binary.little_endian_put_u32(mut digest[4..], d.s[1]) diff --git a/vlib/crypto/rand/utils.v b/vlib/crypto/rand/utils.v index 14cfdb84c2..14796acb84 100644 --- a/vlib/crypto/rand/utils.v +++ b/vlib/crypto/rand/utils.v @@ -38,7 +38,7 @@ pub fn int_u64(max u64) ?u64 { fn bytes_to_u64(b []byte) []u64 { ws := 64/8 - mut z := [u64(0)].repeat((b.len + ws - 1) / ws) + mut z := []u64{len:((b.len + ws - 1) / ws)} mut i := b.len for k := 0; i >= ws; k++ { z[k] = binary.big_endian_u64(b[i-ws..i]) diff --git a/vlib/crypto/rc4/rc4.v b/vlib/crypto/rc4/rc4.v index 2f97c560bb..798fe30119 100644 --- a/vlib/crypto/rc4/rc4.v +++ b/vlib/crypto/rc4/rc4.v @@ -30,7 +30,7 @@ pub fn new_cipher(key []byte) ?Cipher { return error('crypto.rc4: invalid key size ' + key.len.str()) } mut c := Cipher{ - s: [u32(0)].repeat(256) + s: []u32{len:(256)} } for i in 0..256 { c.s[i] = u32(i) diff --git a/vlib/crypto/sha1/sha1.v b/vlib/crypto/sha1/sha1.v index e7fbbe6884..b9fd5d8816 100644 --- a/vlib/crypto/sha1/sha1.v +++ b/vlib/crypto/sha1/sha1.v @@ -40,8 +40,8 @@ mut: } fn (mut d Digest) reset() { - d.x = [byte(0)].repeat(chunk) - d.h = [u32(0)].repeat(5) + d.x = []byte{len:(chunk)} + d.h = []u32{len:(5)} d.h[0] = u32(init0) d.h[1] = u32(init1) d.h[2] = u32(init2) @@ -105,7 +105,7 @@ pub fn (d &Digest) sum(b_in []byte) []byte { fn (mut d Digest) checksum() []byte { mut len := d.len // Padding. Add a 1 bit and 0 bits until 56 bytes mod 64. - mut tmp := [byte(0)].repeat(64) + mut tmp := []byte{len:(64)} tmp[0] = 0x80 @@ -120,7 +120,7 @@ fn (mut d Digest) checksum() []byte { binary.big_endian_put_u64(mut tmp, len) d.write(tmp[..8]) - mut digest := [byte(0)].repeat(size) + mut digest := []byte{len:(size)} binary.big_endian_put_u32(mut digest, d.h[0]) binary.big_endian_put_u32(mut digest[4..], d.h[1]) diff --git a/vlib/crypto/sha1/sha1block_generic.v b/vlib/crypto/sha1/sha1block_generic.v index 55d7a1f1fe..7928823941 100644 --- a/vlib/crypto/sha1/sha1block_generic.v +++ b/vlib/crypto/sha1/sha1block_generic.v @@ -19,7 +19,7 @@ const ( fn block_generic(mut dig Digest, p_ []byte) { mut p := p_ - mut w := [u32(0)].repeat(16) + mut w := []u32{len:(16)} mut h0 := dig.h[0] mut h1 := dig.h[1] mut h2 := dig.h[2] diff --git a/vlib/crypto/sha256/sha256.v b/vlib/crypto/sha256/sha256.v index 5aa34ec382..9665517bf9 100644 --- a/vlib/crypto/sha256/sha256.v +++ b/vlib/crypto/sha256/sha256.v @@ -52,8 +52,8 @@ mut: } fn (mut d Digest) reset() { - d.h = [u32(0)].repeat(8) - d.x = [byte(0)].repeat(chunk) + d.h = []u32{len:(8)} + d.x = []byte{len:(chunk)} if !d.is224 { d.h[0] = u32(init0) d.h[1] = u32(init1) @@ -144,7 +144,7 @@ fn (d &Digest) sum(b_in []byte) []byte { fn (mut d Digest) checksum() []byte { mut len := d.len // Padding. Add a 1 bit and 0 bits until 56 bytes mod 64. - mut tmp := [byte(0)].repeat(64) + mut tmp := []byte{len:(64)} tmp[0] = 0x80 if int(len)%64 < 56 { d.write(tmp[..56-int(len)%64]) @@ -161,7 +161,7 @@ fn (mut d Digest) checksum() []byte { panic('d.nx != 0') } - digest := [byte(0)].repeat(size) + digest := []byte{len:(size)} binary.big_endian_put_u32(mut digest, d.h[0]) binary.big_endian_put_u32(mut digest[4..], d.h[1]) @@ -194,7 +194,7 @@ pub fn sum224(data []byte) []byte { mut d := new224() d.write(data) sum := d.checksum() - sum224 := [byte(0)].repeat(size224) + sum224 := []byte{len:(size224)} copy(sum224, sum[..size224]) return sum224 } diff --git a/vlib/crypto/sha256/sha256block_generic.v b/vlib/crypto/sha256/sha256block_generic.v index dafc014364..55e57b40b9 100644 --- a/vlib/crypto/sha256/sha256block_generic.v +++ b/vlib/crypto/sha256/sha256block_generic.v @@ -83,7 +83,7 @@ const ( fn block_generic(mut dig Digest, p_ []byte) { mut p := p_ - mut w := [u32(0)].repeat(64) + mut w := []u32{len:(64)} mut h0 := dig.h[0] mut h1 := dig.h[1] diff --git a/vlib/crypto/sha512/sha512.v b/vlib/crypto/sha512/sha512.v index 3e87dac01d..08538648f7 100644 --- a/vlib/crypto/sha512/sha512.v +++ b/vlib/crypto/sha512/sha512.v @@ -70,8 +70,8 @@ mut: } fn (mut d Digest) reset() { - d.h = [u64(0)].repeat(8) - d.x = [byte(0)].repeat(chunk) + d.h = []u64{len:(8)} + d.x = []byte{len:(chunk)} match d.function { .sha384 { d.h[0] = init0_384 @@ -212,7 +212,7 @@ fn (d &Digest) sum(b_in []byte) []byte { fn (mut d Digest) checksum() []byte { // Padding. Add a 1 bit and 0 bits until 112 bytes mod 128. mut len := d.len - mut tmp := [byte(0)].repeat(128) + mut tmp := []byte{len:(128)} tmp[0] = 0x80 if int(len) % 128 < 112 { d.write(tmp[..112 - int(len) % 128]) @@ -228,7 +228,7 @@ fn (mut d Digest) checksum() []byte { if d.nx != 0 { panic('d.nx != 0') } - mut digest := [byte(0)].repeat(size) + mut digest := []byte{len:(size)} binary.big_endian_put_u64(mut digest, d.h[0]) binary.big_endian_put_u64(mut digest[8..], d.h[1]) binary.big_endian_put_u64(mut digest[16..], d.h[2]) @@ -254,7 +254,7 @@ pub fn sum384(data []byte) []byte { mut d := new_digest(.sha384) d.write(data) sum := d.checksum() - sum384 := [byte(0)].repeat(size384) + sum384 := []byte{len:(size384)} copy(sum384, sum[..size384]) return sum384 } @@ -264,7 +264,7 @@ pub fn sum512_224(data []byte) []byte { mut d := new_digest(.sha512_224) d.write(data) sum := d.checksum() - sum224 := [byte(0)].repeat(size224) + sum224 := []byte{len:(size224)} copy(sum224, sum[..size224]) return sum224 } @@ -274,7 +274,7 @@ pub fn sum512_256(data []byte) []byte { mut d := new_digest(.sha512_256) d.write(data) sum := d.checksum() - sum256 := [byte(0)].repeat(size256) + sum256 := []byte{len:(size256)} copy(sum256, sum[..size256]) return sum256 } diff --git a/vlib/crypto/sha512/sha512block_generic.v b/vlib/crypto/sha512/sha512block_generic.v index 9b90960ddf..3f1f4818d5 100644 --- a/vlib/crypto/sha512/sha512block_generic.v +++ b/vlib/crypto/sha512/sha512block_generic.v @@ -95,7 +95,7 @@ const ( fn block_generic(mut dig Digest, p_ []byte) { mut p := p_ - mut w := [u64(0)].repeat(80) + mut w := []u64{len:(80)} mut h0 := dig.h[0] mut h1 := dig.h[1] mut h2 := dig.h[2] diff --git a/vlib/net/urllib/urllib.v b/vlib/net/urllib/urllib.v index a53593ab9b..05dd1cb825 100644 --- a/vlib/net/urllib/urllib.v +++ b/vlib/net/urllib/urllib.v @@ -256,14 +256,14 @@ fn escape(s string, mode EncodingMode) string { if space_count == 0 && hex_count == 0 { return s } - buf := [byte(0)].repeat(64) + buf := []byte{len:(64)} mut t := []byte{} required := s.len + 2 * hex_count if required <= buf.len { t = buf[..required] } else { - t = [byte(0)].repeat(required) + t = []byte{len:(required)} } if hex_count == 0 { copy(t, s.bytes()) diff --git a/vlib/rand/mt19937/mt19937_test.v b/vlib/rand/mt19937/mt19937_test.v index e9811f10d3..22076bb648 100644 --- a/vlib/rand/mt19937/mt19937_test.v +++ b/vlib/rand/mt19937/mt19937_test.v @@ -26,7 +26,7 @@ fn mt19937_basic_test() { fn gen_randoms(seed_data []u32, bound int) []u64 { bound_u64 := u64(bound) - mut randoms := [u64(0)].repeat(20) + mut randoms := []u64{len:(20)} mut rnd := mt19937.MT19937RNG{} rnd.seed(seed_data) for i in 0 .. 20 { diff --git a/vlib/rand/musl/musl_rng_test.v b/vlib/rand/musl/musl_rng_test.v index 0bcd2c4302..190eb20358 100644 --- a/vlib/rand/musl/musl_rng_test.v +++ b/vlib/rand/musl/musl_rng_test.v @@ -16,7 +16,7 @@ const ( fn gen_randoms(seed_data []u32, bound int) []u64 { bound_u64 := u64(bound) - mut randoms := [u64(0)].repeat(20) + mut randoms := []u64{len:(20)} mut rnd := musl.MuslRNG{} rnd.seed(seed_data) for i in 0 .. 20 { diff --git a/vlib/rand/splitmix64/splitmix64_test.v b/vlib/rand/splitmix64/splitmix64_test.v index bfd2895b5d..f75564b256 100644 --- a/vlib/rand/splitmix64/splitmix64_test.v +++ b/vlib/rand/splitmix64/splitmix64_test.v @@ -16,7 +16,7 @@ const ( fn gen_randoms(seed_data []u32, bound int) []u64 { bound_u64 := u64(bound) - mut randoms := [u64(0)].repeat(20) + mut randoms := []u64{len:(20)} mut rnd := splitmix64.SplitMix64RNG{} rnd.seed(seed_data) for i in 0 .. 20 { diff --git a/vlib/rand/wyrand/wyrand_test.v b/vlib/rand/wyrand/wyrand_test.v index 42ee859e62..d36190f8d7 100644 --- a/vlib/rand/wyrand/wyrand_test.v +++ b/vlib/rand/wyrand/wyrand_test.v @@ -16,7 +16,7 @@ const ( fn gen_randoms(seed_data []u32, bound int) []u64 { bound_u64 := u64(bound) - mut randoms := [u64(0)].repeat(20) + mut randoms := []u64{len:(20)} mut rnd := wyrand.WyRandRNG{} rnd.seed(seed_data) for i in 0 .. 20 { diff --git a/vlib/regex/regex.v b/vlib/regex/regex.v index 426334bf9e..b4422386a5 100644 --- a/vlib/regex/regex.v +++ b/vlib/regex/regex.v @@ -479,7 +479,7 @@ enum CharClass_parse_state { } fn (re RE) get_char_class(pc int) string { - buf := [byte(0)].repeat(re.cc.len) + buf := []byte{len:(re.cc.len)} mut buf_ptr := &byte(&buf) mut cc_i := re.prog[pc].cc_index diff --git a/vlib/strconv/ftoa/f32_str.v b/vlib/strconv/ftoa/f32_str.v index d3836cd231..55ee20bf49 100644 --- a/vlib/strconv/ftoa/f32_str.v +++ b/vlib/strconv/ftoa/f32_str.v @@ -77,7 +77,7 @@ fn (d Dec32) get_string_32(neg bool, i_n_digit int, i_pad_digit int) string { fw_zeros = pad_digit -out_len } - mut buf := [byte(0)].repeat(out_len + 5 + 1 +1) // sign + mant_len + . + e + e_sign + exp_len(2) + \0 + mut buf := []byte{len:int(out_len + 5 + 1 +1)} // sign + mant_len + . + e + e_sign + exp_len(2) + \0} mut i := 0 if neg { diff --git a/vlib/strconv/ftoa/f64_str.v b/vlib/strconv/ftoa/f64_str.v index 5655addf15..0b110ea03e 100644 --- a/vlib/strconv/ftoa/f64_str.v +++ b/vlib/strconv/ftoa/f64_str.v @@ -90,7 +90,7 @@ fn (d Dec64) get_string_64(neg bool, i_n_digit int, i_pad_digit int) string { fw_zeros = pad_digit - out_len } - mut buf := [byte(0)].repeat(out_len + 6 + 1 +1 + fw_zeros) // sign + mant_len + . + e + e_sign + exp_len(2) + \0 + mut buf := []byte{len:(out_len + 6 + 1 +1 + fw_zeros)} // sign + mant_len + . + e + e_sign + exp_len(2) + \0} mut i := 0 if neg { diff --git a/vlib/sync/pool.v b/vlib/sync/pool.v index ab63474302..90ec0db8d6 100644 --- a/vlib/sync/pool.v +++ b/vlib/sync/pool.v @@ -114,8 +114,8 @@ pub fn (mut pool PoolProcessor) work_on_pointers(items []voidptr) { pool.results = [] pool.thread_contexts = [] pool.items << items - pool.results = [voidptr(0)].repeat(pool.items.len) - pool.thread_contexts << [voidptr(0)].repeat(pool.items.len) + pool.results = []voidptr{len:(pool.items.len)} + pool.thread_contexts << []voidptr{len:(pool.items.len)} pool.waitgroup.add(njobs) for i := 0; i < njobs; i++ { if njobs > 1 { diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 3235f2e0fc..3e103f36b9 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -841,9 +841,9 @@ fn (mut g Gen) for_in(it ast.ForInStmt) { g.writeln(', $key, &($val_styp[]){ $zero }));') } g.stmts(it.stmts) - g.writeln('/* for in map cleanup*/ string_free(&$key);') g.writeln('}') g.writeln('/*for in map cleanup*/') + g.writeln('for (int $idx = 0; $idx < ${keys_tmp}.len; $idx++) { string_free(&(($key_styp*)${keys_tmp}.data)[$idx]); }') g.writeln('array_free(&$keys_tmp);') } else if it.cond_type.has_flag(.variadic) { g.writeln('// FOR IN cond_type/variadic') diff --git a/vlib/v/gen/tests/3.vv b/vlib/v/gen/tests/3.vv index 4c4403145d..15c2bf1a98 100644 --- a/vlib/v/gen/tests/3.vv +++ b/vlib/v/gen/tests/3.vv @@ -25,7 +25,7 @@ fn get_user_opt() ?User { fn (u &User) foo() { age := u.age - zzz := [''].repeat(u.age) + zzz := []string{len:(u.age)} a := 10 if a in [10, 20, 30] { b := 10 diff --git a/vlib/v/token/token.v b/vlib/v/token/token.v index 37689f65e1..ff7a57906c 100644 --- a/vlib/v/token/token.v +++ b/vlib/v/token/token.v @@ -148,7 +148,7 @@ fn build_keys() map[string]Kind { // TODO remove once we have `enum Kind { name('name') if('if') ... }` fn build_token_str() []string { - mut s := [''].repeat(nr_tokens) + mut s := []string{len:(nr_tokens)} s[Kind.unknown] = 'unknown' s[Kind.eof] = 'eof' s[Kind.name] = 'name'