From f077fbd32d898e3d445048a19122f0cb65277787 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Sun, 15 Sep 2019 19:26:05 +1000 Subject: [PATCH] vlib: change `[0;n]` to `[0].repeat(n)` --- compiler/tests/struct_test.v | 2 +- examples/news_fetcher.v | 2 +- examples/spectral.v | 4 ++-- examples/tetris/tetris.v | 2 +- thirdparty/freetype | 1 + vlib/bitfield/bitfield.v | 2 +- vlib/builtin/array_test.v | 12 ++++++------ vlib/crypto/aes/cypher_generic.v | 4 ++-- vlib/crypto/md5/md5.v | 6 +++--- vlib/crypto/rc4/rc4.v | 2 +- vlib/crypto/sha1/sha1.v | 8 ++++---- vlib/crypto/sha1/sha1block_generic.v | 2 +- vlib/crypto/sha256/sha256.v | 10 +++++----- vlib/crypto/sha256/sha256block_generic.v | 2 +- vlib/crypto/sha512/sha512.v | 14 +++++++------- vlib/crypto/sha512/sha512block_generic.v | 2 +- vlib/net/urllib/urllib.v | 4 ++-- vlib/rand/rand_test.v | 2 +- 18 files changed, 41 insertions(+), 40 deletions(-) create mode 160000 thirdparty/freetype diff --git a/compiler/tests/struct_test.v b/compiler/tests/struct_test.v index 8f36f434a2..a55b263176 100644 --- a/compiler/tests/struct_test.v +++ b/compiler/tests/struct_test.v @@ -36,7 +36,7 @@ fn test_struct_levels() { assert c.nums[0] == 4 c.b.a.val = 34 assert c.b.a.val == 34 - c.b.a.nums = [0;0] + c.b.a.nums = [0].repeat(0) c.b.a.nums << 0 c.b.a.nums << 2 assert c.b.a.nums.len == 2 diff --git a/examples/news_fetcher.v b/examples/news_fetcher.v index 17f5eabcc9..4dd16fa967 100644 --- a/examples/news_fetcher.v +++ b/examples/news_fetcher.v @@ -58,7 +58,7 @@ fn main() { } if ids.len > 10 { // ids = ids[:10] - mut tmp := [0 ; 10] + mut tmp := [0].repeat(10) for i := 0 ; i < 10 ; i++ { tmp[i] = ids[i] } diff --git a/examples/spectral.v b/examples/spectral.v index d597fd331d..219314b2f8 100644 --- a/examples/spectral.v +++ b/examples/spectral.v @@ -55,8 +55,8 @@ fn main() { else { n = 0 } - mut u := [f64(1.0);n] - mut v := [f64(1.0);n] + mut u := [f64(1.0)].repeat(n) + mut v := [f64(1.0)].repeat(n) for i := 0; i< 10; i++ { v.a_times_transp(u) diff --git a/examples/tetris/tetris.v b/examples/tetris/tetris.v index bf59ba6dd4..03c1f3722d 100644 --- a/examples/tetris/tetris.v +++ b/examples/tetris/tetris.v @@ -338,7 +338,7 @@ fn (g mut Game) draw_scene() { fn parse_binary_tetro(t_ int) []Block { mut t := t_ - res := [Block{} ; 4] + res := [Block{}].repeat(4) mut cnt := 0 horizontal := t == 9// special case for the horizontal line for i := 0; i <= 3; i++ { diff --git a/thirdparty/freetype b/thirdparty/freetype new file mode 160000 index 0000000000..e4504fd25d --- /dev/null +++ b/thirdparty/freetype @@ -0,0 +1 @@ +Subproject commit e4504fd25d7d23797ccfef336a33491c0d654129 diff --git a/vlib/bitfield/bitfield.v b/vlib/bitfield/bitfield.v index 7150ef565c..ab3c0b72a7 100644 --- a/vlib/bitfield/bitfield.v +++ b/vlib/bitfield/bitfield.v @@ -481,7 +481,7 @@ pub fn (instance mut BitField) resize(new_size int) { new_bitnslots := bitnslots(new_size) old_size := instance.size old_bitnslots := bitnslots(old_size) - mut field := [u32(0); new_bitnslots] + mut field := [u32(0)].repeat(new_bitnslots) for i := 0; i < old_bitnslots && i < new_bitnslots; i++ { field[i] = instance.field[i] } diff --git a/vlib/builtin/array_test.v b/vlib/builtin/array_test.v index f9f1c74a7c..a2a551967d 100644 --- a/vlib/builtin/array_test.v +++ b/vlib/builtin/array_test.v @@ -46,7 +46,7 @@ fn test_short() { } fn test_large() { - mut a := [0; 0] + mut a := [0].repeat(0) for i := 0; i < 10000; i++ { a << i } @@ -88,28 +88,28 @@ fn test_strings() { } fn test_repeat() { - a := [0; 5] + a := [0].repeat(5) assert a.len == 5 assert a[0] == 0 && a[1] == 0 && a[2] == 0 && a[3] == 0 && a[4] == 0 - b := [7; 3] + b := [7].repeat(3) assert b.len == 3 assert b[0] == 7 && b[1] == 7 && b[2] == 7 { - mut aa := [1.1 ; 10] + mut aa := [1.1].repeat(10) // FIXME: assert aa[0] == 1.1 will fail, need fix assert aa[0] == f32(1.1) assert aa[5] == f32(1.1) assert aa[9] == f32(1.1) } { - mut aa := [f32(1.1) ; 10] + mut aa := [f32(1.1)].repeat(10) assert aa[0] == f32(1.1) assert aa[5] == f32(1.1) assert aa[9] == f32(1.1) } { - aa := [f64(1.1) ; 10] + aa := [f64(1.1)].repeat(10) assert aa[0] == f64(1.1) assert aa[5] == f64(1.1) assert aa[9] == f64(1.1) diff --git a/vlib/crypto/aes/cypher_generic.v b/vlib/crypto/aes/cypher_generic.v index 813d4a093b..c9eb191c07 100644 --- a/vlib/crypto/aes/cypher_generic.v +++ b/vlib/crypto/aes/cypher_generic.v @@ -14,8 +14,8 @@ import ( fn new_cipher_generic(key []byte) AesCipher { n := key.len + 28 mut c := AesCipher{ - enc: [u32(0); n] - dec: [u32(0); n] + enc: [u32(0)].repeat(n) + dec: [u32(0)].repeat(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 d12ba46f19..7a63ab3c07 100644 --- a/vlib/crypto/md5/md5.v +++ b/vlib/crypto/md5/md5.v @@ -38,8 +38,8 @@ mut: } fn (d mut Digest) reset() { - d.s = [u32(0); 4] - d.x = [byte(0); BlockSize] + d.s = [u32(0)].repeat(4) + d.x = [byte(0)].repeat(BlockSize) d.s[0] = u32(Init0) d.s[1] = u32(Init1) d.s[2] = u32(Init2) @@ -116,7 +116,7 @@ pub fn (d mut Digest) checksum() []byte { panic('d.nx != 0') } - digest := [byte(0); Size] + digest := [byte(0)].repeat(Size) binary.little_endian_put_u32(mut digest, d.s[0]) binary.little_endian_put_u32(mut digest.right(4), d.s[1]) diff --git a/vlib/crypto/rc4/rc4.v b/vlib/crypto/rc4/rc4.v index 4ebfd4a8e7..4694d4b8fe 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); 256] + s: [u32(0)].repeat(256) } for i := 0; i < 256; i++ { c.s[i] = u32(i) diff --git a/vlib/crypto/sha1/sha1.v b/vlib/crypto/sha1/sha1.v index 9a7e3720d9..6d906def09 100644 --- a/vlib/crypto/sha1/sha1.v +++ b/vlib/crypto/sha1/sha1.v @@ -40,8 +40,8 @@ mut: } fn (d mut Digest) reset() { - d.x = [byte(0); Chunk] - d.h = [u32(0); 5] + d.x = [byte(0)].repeat(Chunk) + d.h = [u32(0)].repeat(5) d.h[0] = u32(Init0) d.h[1] = u32(Init1) d.h[2] = u32(Init2) @@ -104,7 +104,7 @@ pub fn (d &Digest) sum(b_in mut []byte) []byte { fn (d mut Digest) checksum() []byte { mut len := d.len // Padding. Add a 1 bit and 0 bits until 56 bytes mod 64. - mut tmp := [byte(0); 64] + mut tmp := [byte(0)].repeat(64) tmp[0] = 0x80 @@ -119,7 +119,7 @@ fn (d mut Digest) checksum() []byte { binary.big_endian_put_u64(mut tmp, len) d.write(tmp.left(8)) - mut digest := [byte(0); Size] + mut digest := [byte(0)].repeat(Size) binary.big_endian_put_u32(mut digest, d.h[0]) binary.big_endian_put_u32(mut digest.right(4), d.h[1]) diff --git a/vlib/crypto/sha1/sha1block_generic.v b/vlib/crypto/sha1/sha1block_generic.v index ed889a1f89..27516af7bc 100644 --- a/vlib/crypto/sha1/sha1block_generic.v +++ b/vlib/crypto/sha1/sha1block_generic.v @@ -19,7 +19,7 @@ const ( fn block_generic(dig mut Digest, p_ []byte) { mut p := p_ - mut w := [u32(0); 16] + mut w := [u32(0)].repeat(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 7ba0aabf29..52728a59b5 100644 --- a/vlib/crypto/sha256/sha256.v +++ b/vlib/crypto/sha256/sha256.v @@ -52,8 +52,8 @@ mut: } fn (d mut Digest) reset() { - d.h = [u32(0); 8] - d.x = [byte(0); Chunk] + d.h = [u32(0)].repeat(8) + d.x = [byte(0)].repeat(Chunk) if !d.is224 { d.h[0] = u32(Init0) d.h[1] = u32(Init1) @@ -143,7 +143,7 @@ fn (d &Digest) sum(b_in mut []byte) []byte { fn (d mut Digest) checksum() []byte { mut len := d.len // Padding. Add a 1 bit and 0 bits until 56 bytes mod 64. - mut tmp := [byte(0); 64] + mut tmp := [byte(0)].repeat(64) tmp[0] = 0x80 if int(len)%64 < 56 { d.write(tmp.left(56-int(len)%64)) @@ -160,7 +160,7 @@ fn (d mut Digest) checksum() []byte { panic('d.nx != 0') } - digest := [byte(0); Size] + digest := [byte(0)].repeat(Size) binary.big_endian_put_u32(mut digest, d.h[0]) binary.big_endian_put_u32(mut digest.right(4), d.h[1]) @@ -193,7 +193,7 @@ pub fn sum224(data []byte) []byte { mut d := new224() d.write(data) sum := d.checksum() - mut sum224 := [byte(0); Size224] + mut sum224 := [byte(0)].repeat(Size224) copy(sum224, sum.left(Size224)) return sum224 } diff --git a/vlib/crypto/sha256/sha256block_generic.v b/vlib/crypto/sha256/sha256block_generic.v index 8589704814..be015afa01 100644 --- a/vlib/crypto/sha256/sha256block_generic.v +++ b/vlib/crypto/sha256/sha256block_generic.v @@ -83,7 +83,7 @@ const ( fn block_generic(dig mut Digest, p_ []byte) { mut p := p_ - mut w := [u32(0); 64] + mut w := [u32(0)].repeat(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 f06bdd768c..61936596c5 100644 --- a/vlib/crypto/sha512/sha512.v +++ b/vlib/crypto/sha512/sha512.v @@ -76,8 +76,8 @@ mut: } fn (d mut Digest) reset() { - d.h = [u64(0); 8] - d.x = [byte(0); Chunk] + d.h = [u64(0)].repeat(8) + d.x = [byte(0)].repeat(Chunk) switch d.function { case crypto.Hash.SHA384: d.h[0] = Init0_384 @@ -206,7 +206,7 @@ fn (d mut Digest) sum(b_in mut []byte) []byte { fn (d mut Digest) checksum() []byte { // Padding. Add a 1 bit and 0 bits until 112 bytes mod 128. mut len := d.len - mut tmp := [byte(0); 128] + mut tmp := [byte(0)].repeat(128) tmp[0] = 0x80 if int(len)%128 < 112 { @@ -226,7 +226,7 @@ fn (d mut Digest) checksum() []byte { panic('d.nx != 0') } - mut digest := [byte(0); Size] + mut digest := [byte(0)].repeat(Size) binary.big_endian_put_u64(mut digest, d.h[0]) binary.big_endian_put_u64(mut digest.right(8), d.h[1]) @@ -254,7 +254,7 @@ pub fn sum384(data []byte) []byte { mut d := _new(crypto.Hash.SHA384) d.write(data) sum := d.checksum() - mut sum384 := [byte(0); Size384] + mut sum384 := [byte(0)].repeat(Size384) copy(sum384, sum.left(Size384)) return sum384 } @@ -264,7 +264,7 @@ pub fn sum512_224(data []byte) []byte { mut d := _new(crypto.Hash.SHA512_224) d.write(data) sum := d.checksum() - mut sum224 := [byte(0); Size224] + mut sum224 := [byte(0)].repeat(Size224) copy(sum224, sum.left(Size224)) return sum224 } @@ -274,7 +274,7 @@ pub fn sum512_256(data []byte) []byte { mut d := _new(crypto.Hash.SHA512_256) d.write(data) sum := d.checksum() - mut sum256 := [byte(0); Size256] + mut sum256 := [byte(0)].repeat(Size256) copy(sum256, sum.left(Size256)) return sum256 } diff --git a/vlib/crypto/sha512/sha512block_generic.v b/vlib/crypto/sha512/sha512block_generic.v index a2a7a9a9a0..9344484548 100644 --- a/vlib/crypto/sha512/sha512block_generic.v +++ b/vlib/crypto/sha512/sha512block_generic.v @@ -97,7 +97,7 @@ const( fn block_generic(dig mut Digest, p_ []byte) { mut p := p_ - mut w := [u64(0); 80] + mut w := [u64(0)].repeat(80) mut h0 := dig.h[0] mut h1 := dig.h[1] diff --git a/vlib/net/urllib/urllib.v b/vlib/net/urllib/urllib.v index f035fd1692..0bff386b07 100644 --- a/vlib/net/urllib/urllib.v +++ b/vlib/net/urllib/urllib.v @@ -247,14 +247,14 @@ fn escape(s string, mode EncodingMode) string { return s } - mut buf := [byte(0); 64] + mut buf := [byte(0)].repeat(64) mut t := []byte required := s.len + 2*hex_count if required <= buf.len { t = buf.left(required) } else { - t = [byte(0); required] + t = [byte(0)].repeat(required) } if hex_count == 0 { diff --git a/vlib/rand/rand_test.v b/vlib/rand/rand_test.v index 737dfbb282..cdfc193cb4 100644 --- a/vlib/rand/rand_test.v +++ b/vlib/rand/rand_test.v @@ -1,7 +1,7 @@ import rand fn gen_randoms(seed int) []int { - mut randoms := [0; 20] + mut randoms := [0].repeat(20) rand.seed(seed) for i in 0..20 { randoms[i] = rand.next(100)