aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-01-27 17:43:42 +0000
committerGinger Bill <bill@gingerbill.org>2017-01-27 17:43:42 +0000
commit92453369c5558feaaaa116fbc54968b087e1aeab (patch)
treea00501fdc52f69c7dd7c415e103b9b13d51e6ad5 /core
parent832009f33acc573d44dd9dfb470ad8fef72216ff (diff)
Remove while loop and readd c-style for loops i.e. all loops are just `for`
Diffstat (limited to 'core')
-rw-r--r--core/atomic.odin4
-rw-r--r--core/fmt.odin13
-rw-r--r--core/hash.odin2
-rw-r--r--core/mem.odin5
-rw-r--r--core/os_windows.odin2
-rw-r--r--core/utf8.odin7
6 files changed, 15 insertions, 18 deletions
diff --git a/core/atomic.odin b/core/atomic.odin
index cc381300e..3be3c1d40 100644
--- a/core/atomic.odin
+++ b/core/atomic.odin
@@ -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);
diff --git a/core/fmt.odin b/core/fmt.odin
index f7c11015e..bd11d05e0 100644
--- a/core/fmt.odin
+++ b/core/fmt.odin
@@ -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);
diff --git a/core/hash.odin b/core/hash.odin
index 7348bef53..b2d6f0226 100644
--- a/core/hash.odin
+++ b/core/hash.odin
@@ -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;
diff --git a/core/mem.odin b/core/mem.odin
index 1ad80137d..5f1bf378b 100644
--- a/core/mem.odin
+++ b/core/mem.odin
@@ -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;
diff --git a/core/os_windows.odin b/core/os_windows.odin
index acfb02116..4127d6242 100644
--- a/core/os_windows.odin
+++ b/core/os_windows.odin
@@ -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;
diff --git a/core/utf8.odin b/core/utf8.odin
index 7730f94be..8720e1f20 100644
--- a/core/utf8.odin
+++ b/core/utf8.odin
@@ -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