vlib: change `[0;n]` to `[0].repeat(n)`

pull/1987/head
joe-conigliaro 2019-09-15 19:26:05 +10:00 committed by Alexander Medvednikov
parent 602e472b8a
commit f077fbd32d
18 changed files with 41 additions and 40 deletions

View File

@ -36,7 +36,7 @@ fn test_struct_levels() {
assert c.nums[0] == 4 assert c.nums[0] == 4
c.b.a.val = 34 c.b.a.val = 34
assert 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 << 0
c.b.a.nums << 2 c.b.a.nums << 2
assert c.b.a.nums.len == 2 assert c.b.a.nums.len == 2

View File

@ -58,7 +58,7 @@ fn main() {
} }
if ids.len > 10 { if ids.len > 10 {
// ids = ids[:10] // ids = ids[:10]
mut tmp := [0 ; 10] mut tmp := [0].repeat(10)
for i := 0 ; i < 10 ; i++ { for i := 0 ; i < 10 ; i++ {
tmp[i] = ids[i] tmp[i] = ids[i]
} }

View File

@ -55,8 +55,8 @@ fn main() {
else { else {
n = 0 n = 0
} }
mut u := [f64(1.0);n] mut u := [f64(1.0)].repeat(n)
mut v := [f64(1.0);n] mut v := [f64(1.0)].repeat(n)
for i := 0; i< 10; i++ { for i := 0; i< 10; i++ {
v.a_times_transp(u) v.a_times_transp(u)

View File

@ -338,7 +338,7 @@ fn (g mut Game) draw_scene() {
fn parse_binary_tetro(t_ int) []Block { fn parse_binary_tetro(t_ int) []Block {
mut t := t_ mut t := t_
res := [Block{} ; 4] res := [Block{}].repeat(4)
mut cnt := 0 mut cnt := 0
horizontal := t == 9// special case for the horizontal line horizontal := t == 9// special case for the horizontal line
for i := 0; i <= 3; i++ { for i := 0; i <= 3; i++ {

1
thirdparty/freetype vendored 160000

@ -0,0 +1 @@
Subproject commit e4504fd25d7d23797ccfef336a33491c0d654129

View File

@ -481,7 +481,7 @@ pub fn (instance mut BitField) resize(new_size int) {
new_bitnslots := bitnslots(new_size) new_bitnslots := bitnslots(new_size)
old_size := instance.size old_size := instance.size
old_bitnslots := bitnslots(old_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++ { for i := 0; i < old_bitnslots && i < new_bitnslots; i++ {
field[i] = instance.field[i] field[i] = instance.field[i]
} }

View File

@ -46,7 +46,7 @@ fn test_short() {
} }
fn test_large() { fn test_large() {
mut a := [0; 0] mut a := [0].repeat(0)
for i := 0; i < 10000; i++ { for i := 0; i < 10000; i++ {
a << i a << i
} }
@ -88,28 +88,28 @@ fn test_strings() {
} }
fn test_repeat() { fn test_repeat() {
a := [0; 5] a := [0].repeat(5)
assert a.len == 5 assert a.len == 5
assert a[0] == 0 && a[1] == 0 && a[2] == 0 && a[3] == 0 && a[4] == 0 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.len == 3
assert b[0] == 7 && b[1] == 7 && b[2] == 7 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 // FIXME: assert aa[0] == 1.1 will fail, need fix
assert aa[0] == f32(1.1) assert aa[0] == f32(1.1)
assert aa[5] == f32(1.1) assert aa[5] == f32(1.1)
assert aa[9] == 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[0] == f32(1.1)
assert aa[5] == f32(1.1) assert aa[5] == f32(1.1)
assert aa[9] == 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[0] == f64(1.1)
assert aa[5] == f64(1.1) assert aa[5] == f64(1.1)
assert aa[9] == f64(1.1) assert aa[9] == f64(1.1)

View File

@ -14,8 +14,8 @@ import (
fn new_cipher_generic(key []byte) AesCipher { fn new_cipher_generic(key []byte) AesCipher {
n := key.len + 28 n := key.len + 28
mut c := AesCipher{ mut c := AesCipher{
enc: [u32(0); n] enc: [u32(0)].repeat(n)
dec: [u32(0); n] dec: [u32(0)].repeat(n)
} }
expand_key_generic(key, mut c.enc, mut c.dec) expand_key_generic(key, mut c.enc, mut c.dec)
return c return c

View File

@ -38,8 +38,8 @@ mut:
} }
fn (d mut Digest) reset() { fn (d mut Digest) reset() {
d.s = [u32(0); 4] d.s = [u32(0)].repeat(4)
d.x = [byte(0); BlockSize] d.x = [byte(0)].repeat(BlockSize)
d.s[0] = u32(Init0) d.s[0] = u32(Init0)
d.s[1] = u32(Init1) d.s[1] = u32(Init1)
d.s[2] = u32(Init2) d.s[2] = u32(Init2)
@ -116,7 +116,7 @@ pub fn (d mut Digest) checksum() []byte {
panic('d.nx != 0') 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, d.s[0])
binary.little_endian_put_u32(mut digest.right(4), d.s[1]) binary.little_endian_put_u32(mut digest.right(4), d.s[1])

View File

@ -30,7 +30,7 @@ pub fn new_cipher(key []byte) ?Cipher {
return error('crypto.rc4: invalid key size ' + key.len.str()) return error('crypto.rc4: invalid key size ' + key.len.str())
} }
mut c := Cipher{ mut c := Cipher{
s: [u32(0); 256] s: [u32(0)].repeat(256)
} }
for i := 0; i < 256; i++ { for i := 0; i < 256; i++ {
c.s[i] = u32(i) c.s[i] = u32(i)

View File

@ -40,8 +40,8 @@ mut:
} }
fn (d mut Digest) reset() { fn (d mut Digest) reset() {
d.x = [byte(0); Chunk] d.x = [byte(0)].repeat(Chunk)
d.h = [u32(0); 5] d.h = [u32(0)].repeat(5)
d.h[0] = u32(Init0) d.h[0] = u32(Init0)
d.h[1] = u32(Init1) d.h[1] = u32(Init1)
d.h[2] = u32(Init2) 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 { fn (d mut Digest) checksum() []byte {
mut len := d.len mut len := d.len
// Padding. Add a 1 bit and 0 bits until 56 bytes mod 64. // 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 tmp[0] = 0x80
@ -119,7 +119,7 @@ fn (d mut Digest) checksum() []byte {
binary.big_endian_put_u64(mut tmp, len) binary.big_endian_put_u64(mut tmp, len)
d.write(tmp.left(8)) 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, d.h[0])
binary.big_endian_put_u32(mut digest.right(4), d.h[1]) binary.big_endian_put_u32(mut digest.right(4), d.h[1])

View File

@ -19,7 +19,7 @@ const (
fn block_generic(dig mut Digest, p_ []byte) { fn block_generic(dig mut Digest, p_ []byte) {
mut p := p_ mut p := p_
mut w := [u32(0); 16] mut w := [u32(0)].repeat(16)
mut h0 := dig.h[0] mut h0 := dig.h[0]
mut h1 := dig.h[1] mut h1 := dig.h[1]
mut h2 := dig.h[2] mut h2 := dig.h[2]

View File

@ -52,8 +52,8 @@ mut:
} }
fn (d mut Digest) reset() { fn (d mut Digest) reset() {
d.h = [u32(0); 8] d.h = [u32(0)].repeat(8)
d.x = [byte(0); Chunk] d.x = [byte(0)].repeat(Chunk)
if !d.is224 { if !d.is224 {
d.h[0] = u32(Init0) d.h[0] = u32(Init0)
d.h[1] = u32(Init1) d.h[1] = u32(Init1)
@ -143,7 +143,7 @@ fn (d &Digest) sum(b_in mut []byte) []byte {
fn (d mut Digest) checksum() []byte { fn (d mut Digest) checksum() []byte {
mut len := d.len mut len := d.len
// Padding. Add a 1 bit and 0 bits until 56 bytes mod 64. // 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 tmp[0] = 0x80
if int(len)%64 < 56 { if int(len)%64 < 56 {
d.write(tmp.left(56-int(len)%64)) d.write(tmp.left(56-int(len)%64))
@ -160,7 +160,7 @@ fn (d mut Digest) checksum() []byte {
panic('d.nx != 0') 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, d.h[0])
binary.big_endian_put_u32(mut digest.right(4), d.h[1]) 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() mut d := new224()
d.write(data) d.write(data)
sum := d.checksum() sum := d.checksum()
mut sum224 := [byte(0); Size224] mut sum224 := [byte(0)].repeat(Size224)
copy(sum224, sum.left(Size224)) copy(sum224, sum.left(Size224))
return sum224 return sum224
} }

View File

@ -83,7 +83,7 @@ const (
fn block_generic(dig mut Digest, p_ []byte) { fn block_generic(dig mut Digest, p_ []byte) {
mut p := p_ mut p := p_
mut w := [u32(0); 64] mut w := [u32(0)].repeat(64)
mut h0 := dig.h[0] mut h0 := dig.h[0]
mut h1 := dig.h[1] mut h1 := dig.h[1]

View File

@ -76,8 +76,8 @@ mut:
} }
fn (d mut Digest) reset() { fn (d mut Digest) reset() {
d.h = [u64(0); 8] d.h = [u64(0)].repeat(8)
d.x = [byte(0); Chunk] d.x = [byte(0)].repeat(Chunk)
switch d.function { switch d.function {
case crypto.Hash.SHA384: case crypto.Hash.SHA384:
d.h[0] = Init0_384 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 { fn (d mut Digest) checksum() []byte {
// Padding. Add a 1 bit and 0 bits until 112 bytes mod 128. // Padding. Add a 1 bit and 0 bits until 112 bytes mod 128.
mut len := d.len mut len := d.len
mut tmp := [byte(0); 128] mut tmp := [byte(0)].repeat(128)
tmp[0] = 0x80 tmp[0] = 0x80
if int(len)%128 < 112 { if int(len)%128 < 112 {
@ -226,7 +226,7 @@ fn (d mut Digest) checksum() []byte {
panic('d.nx != 0') 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, d.h[0])
binary.big_endian_put_u64(mut digest.right(8), d.h[1]) 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) mut d := _new(crypto.Hash.SHA384)
d.write(data) d.write(data)
sum := d.checksum() sum := d.checksum()
mut sum384 := [byte(0); Size384] mut sum384 := [byte(0)].repeat(Size384)
copy(sum384, sum.left(Size384)) copy(sum384, sum.left(Size384))
return sum384 return sum384
} }
@ -264,7 +264,7 @@ pub fn sum512_224(data []byte) []byte {
mut d := _new(crypto.Hash.SHA512_224) mut d := _new(crypto.Hash.SHA512_224)
d.write(data) d.write(data)
sum := d.checksum() sum := d.checksum()
mut sum224 := [byte(0); Size224] mut sum224 := [byte(0)].repeat(Size224)
copy(sum224, sum.left(Size224)) copy(sum224, sum.left(Size224))
return sum224 return sum224
} }
@ -274,7 +274,7 @@ pub fn sum512_256(data []byte) []byte {
mut d := _new(crypto.Hash.SHA512_256) mut d := _new(crypto.Hash.SHA512_256)
d.write(data) d.write(data)
sum := d.checksum() sum := d.checksum()
mut sum256 := [byte(0); Size256] mut sum256 := [byte(0)].repeat(Size256)
copy(sum256, sum.left(Size256)) copy(sum256, sum.left(Size256))
return sum256 return sum256
} }

View File

@ -97,7 +97,7 @@ const(
fn block_generic(dig mut Digest, p_ []byte) { fn block_generic(dig mut Digest, p_ []byte) {
mut p := p_ mut p := p_
mut w := [u64(0); 80] mut w := [u64(0)].repeat(80)
mut h0 := dig.h[0] mut h0 := dig.h[0]
mut h1 := dig.h[1] mut h1 := dig.h[1]

View File

@ -247,14 +247,14 @@ fn escape(s string, mode EncodingMode) string {
return s return s
} }
mut buf := [byte(0); 64] mut buf := [byte(0)].repeat(64)
mut t := []byte mut t := []byte
required := s.len + 2*hex_count required := s.len + 2*hex_count
if required <= buf.len { if required <= buf.len {
t = buf.left(required) t = buf.left(required)
} else { } else {
t = [byte(0); required] t = [byte(0)].repeat(required)
} }
if hex_count == 0 { if hex_count == 0 {

View File

@ -1,7 +1,7 @@
import rand import rand
fn gen_randoms(seed int) []int { fn gen_randoms(seed int) []int {
mut randoms := [0; 20] mut randoms := [0].repeat(20)
rand.seed(seed) rand.seed(seed)
for i in 0..20 { for i in 0..20 {
randoms[i] = rand.next(100) randoms[i] = rand.next(100)