Remove while loop and readd c-style for loops i.e. all loops are just for

This commit is contained in:
Ginger Bill
2017-01-27 17:43:42 +00:00
parent 832009f33a
commit 92453369c5
11 changed files with 201 additions and 139 deletions
+2 -2
View File
@@ -36,7 +36,7 @@ fetch_or :: proc(a: ^i32, operand: i32) -> i32 {
spin_lock :: proc(a: ^i32, time_out: int) -> bool { // NOTE(bill) time_out = -1 as default
old_value := compare_exchange(a, 1, 0);
counter := 0;
while old_value != 0 && (time_out < 0 || counter < time_out) {
for old_value != 0 && (time_out < 0 || counter < time_out) {
counter += 1;
yield_thread();
old_value = compare_exchange(a, 1, 0);
@@ -80,7 +80,7 @@ fetch_or :: proc(a: ^i64, operand: i64) -> i64 {
spin_lock :: proc(a: ^i64, time_out: int) -> bool { // NOTE(bill) time_out = -1 as default
old_value := compare_exchange(a, 1, 0);
counter := 0;
while old_value != 0 && (time_out < 0 || counter < time_out) {
for old_value != 0 && (time_out < 0 || counter < time_out) {
counter += 1;
yield_thread();
old_value = compare_exchange(a, 1, 0);
+6 -7
View File
@@ -460,7 +460,7 @@ fmt_integer :: proc(fi: ^Fmt_Info, u: u64, base: int, signed: bool, digits: stri
panic("fmt_integer: unknown base, whoops");
}
while b := cast(u64)base; u >= b {
for b := cast(u64)base; u >= b; {
i -= 1;
next := u / b;
buf[i] = digits[u%b];
@@ -468,7 +468,7 @@ fmt_integer :: proc(fi: ^Fmt_Info, u: u64, base: int, signed: bool, digits: stri
}
i -= 1;
buf[i] = digits[u];
while i > 0 && prec > buf.count-i {
for i > 0 && prec > buf.count-i {
i -= 1;
buf[i] = '0';
}
@@ -598,7 +598,7 @@ fmt_float :: proc(fi: ^Fmt_Info, v: f64, bit_size: int, verb: rune) {
case fi.space: fill = ' ';
}
while width > 0 {
for width > 0 {
width -= 1;
buffer_write_byte(fi.buf, fill);
}
@@ -885,11 +885,11 @@ bprintf :: proc(b: ^Buffer, fmt: string, args: ..any) -> int {
end := fmt.count;
arg_index := 0;
was_prev_index := false;
while i := 0; i < end {
for i := 0; i < end; {
fi = Fmt_Info{buf = b, good_arg_index = true};
prev_i := i;
while i < end && fmt[i] != '%' {
for i < end && fmt[i] != '%' {
i += 1;
}
if i > prev_i {
@@ -903,7 +903,7 @@ bprintf :: proc(b: ^Buffer, fmt: string, args: ..any) -> int {
i += 1;
while i < end {
for ; i < end; i += 1 {
skip_loop := false;
c := fmt[i];
match c {
@@ -925,7 +925,6 @@ bprintf :: proc(b: ^Buffer, fmt: string, args: ..any) -> int {
if skip_loop {
break;
}
i += 1;
}
arg_index, i, was_prev_index = arg_number(^fi, arg_index, fmt, i, args.count);
+1 -1
View File
@@ -108,7 +108,7 @@ murmur64 :: proc(data_: rawptr, len: int) -> u64 {
data := slice_ptr(cast(^u32)data_, len/size_of(u32));
i := 0;
while len >= 8 {
for len >= 8 {
k1, k2: u32;
k1 = data[i]; i += 1;
k1 *= m;
+2 -3
View File
@@ -75,14 +75,13 @@ allocation_header_fill :: proc(header: ^Allocation_Header, data: rawptr, size: i
header.size = size;
ptr := cast(^int)(header+1);
while i := 0; cast(rawptr)ptr < data {
for i := 0; cast(rawptr)ptr < data; i += 1 {
(ptr+i)^ = -1;
i += 1;
}
}
allocation_header :: proc(data: rawptr) -> ^Allocation_Header {
p := cast(^int)data;
while (p-1)^ == -1 {
for (p-1)^ == -1 {
p = (p-1);
}
return cast(^Allocation_Header)p-1;
+1 -1
View File
@@ -223,7 +223,7 @@ read_entire_file :: proc(name: string) -> ([]byte, bool) {
single_read_length: i32;
total_read: i64;
while total_read < length {
for total_read < length {
remaining := length - total_read;
to_read: u32;
MAX :: 1<<32-1;
+3 -4
View File
@@ -143,8 +143,7 @@ valid_rune :: proc(r: rune) -> bool {
valid_string :: proc(s: string) -> bool {
n := s.count;
i := 0;
while i < n {
for i := 0; i < n; {
si := s[i];
if si < RUNE_SELF { // ascii
i += 1;
@@ -178,8 +177,8 @@ valid_string :: proc(s: string) -> bool {
rune_count :: proc(s: string) -> int {
count := 0;
n := s.count;
i := 0;
while i < n {
for i := 0; i < n; {
defer count += 1;
si := s[i];
if si < RUNE_SELF { // ascii