Replace x in &y Use &v in y syntax through core & vendor for switch/for statements

This commit is contained in:
gingerBill
2023-06-26 15:42:57 +01:00
parent 00d60e28c2
commit 3dec55f009
14 changed files with 33 additions and 33 deletions
@@ -32,7 +32,7 @@ init :: proc(sorter: ^$S/Sorter($K)) {
} }
destroy :: proc(sorter: ^$S/Sorter($K)) { destroy :: proc(sorter: ^$S/Sorter($K)) {
for _, v in &sorter.relations { for _, v in sorter.relations {
delete(v.dependents) delete(v.dependents)
} }
delete(sorter.relations) delete(sorter.relations)
@@ -80,7 +80,7 @@ sort :: proc(sorter: ^$S/Sorter($K)) -> (sorted, cycled: [dynamic]K) {
} }
} }
for root in &sorted do for k, _ in relations[root].dependents { for root in sorted do for k, _ in relations[root].dependents {
relation := &relations[k] relation := &relations[k]
relation.dependencies -= 1 relation.dependencies -= 1
if relation.dependencies == 0 { if relation.dependencies == 0 {
+2 -2
View File
@@ -83,7 +83,7 @@ read :: proc(data: []byte, filename := "<input>", print_error := false, allocato
meta_data = make([]Meta, int(capacity)) meta_data = make([]Meta, int(capacity))
count := 0 count := 0
defer meta_data = meta_data[:count] defer meta_data = meta_data[:count]
for m in &meta_data { for &m in meta_data {
m.name = read_name(r) or_return m.name = read_name(r) or_return
type := read_value(r, Meta_Value_Type) or_return type := read_value(r, Meta_Value_Type) or_return
@@ -116,7 +116,7 @@ read :: proc(data: []byte, filename := "<input>", print_error := false, allocato
layer_count := 0 layer_count := 0
layers = make(Layer_Stack, stack_count) layers = make(Layer_Stack, stack_count)
defer layers = layers[:layer_count] defer layers = layers[:layer_count]
for layer in &layers { for &layer in layers {
layer.name = read_name(r) or_return layer.name = read_name(r) or_return
layer.components = read_value(r, u8) or_return layer.components = read_value(r, u8) or_return
type := read_value(r, Layer_Data_Type) or_return type := read_value(r, Layer_Data_Type) or_return
+5 -5
View File
@@ -72,7 +72,7 @@ unmarshal_string :: proc(data: string, ptr: ^$T, spec := DEFAULT_SPECIFICATION,
@(private) @(private)
assign_bool :: proc(val: any, b: bool) -> bool { assign_bool :: proc(val: any, b: bool) -> bool {
v := reflect.any_core(val) v := reflect.any_core(val)
switch dst in &v { switch &dst in v {
case bool: dst = bool(b) case bool: dst = bool(b)
case b8: dst = b8 (b) case b8: dst = b8 (b)
case b16: dst = b16 (b) case b16: dst = b16 (b)
@@ -85,7 +85,7 @@ assign_bool :: proc(val: any, b: bool) -> bool {
@(private) @(private)
assign_int :: proc(val: any, i: $T) -> bool { assign_int :: proc(val: any, i: $T) -> bool {
v := reflect.any_core(val) v := reflect.any_core(val)
switch dst in &v { switch &dst in v {
case i8: dst = i8 (i) case i8: dst = i8 (i)
case i16: dst = i16 (i) case i16: dst = i16 (i)
case i16le: dst = i16le (i) case i16le: dst = i16le (i)
@@ -122,7 +122,7 @@ assign_int :: proc(val: any, i: $T) -> bool {
@(private) @(private)
assign_float :: proc(val: any, f: $T) -> bool { assign_float :: proc(val: any, f: $T) -> bool {
v := reflect.any_core(val) v := reflect.any_core(val)
switch dst in &v { switch &dst in v {
case f16: dst = f16 (f) case f16: dst = f16 (f)
case f16le: dst = f16le(f) case f16le: dst = f16le(f)
case f16be: dst = f16be(f) case f16be: dst = f16be(f)
@@ -150,7 +150,7 @@ assign_float :: proc(val: any, f: $T) -> bool {
@(private) @(private)
unmarshal_string_token :: proc(p: ^Parser, val: any, str: string, ti: ^reflect.Type_Info) -> bool { unmarshal_string_token :: proc(p: ^Parser, val: any, str: string, ti: ^reflect.Type_Info) -> bool {
val := val val := val
switch dst in &val { switch &dst in val {
case string: case string:
dst = str dst = str
return true return true
@@ -215,7 +215,7 @@ unmarshal_value :: proc(p: ^Parser, v: any) -> (err: Unmarshal_Error) {
} }
} }
switch dst in &v { switch &dst in v {
// Handle json.Value as an unknown type // Handle json.Value as an unknown type
case Value: case Value:
dst = parse_value(p) or_return dst = parse_value(p) or_return
+6 -6
View File
@@ -161,18 +161,18 @@ save_to_buffer :: proc(img: ^Image, custom_info: Info = {}, allocator := context
// convert from native endianness // convert from native endianness
if img.depth == 16 { if img.depth == 16 {
pixels := mem.slice_data_cast([]u16be, data.buf[len(header_buf):]) pixels := mem.slice_data_cast([]u16be, data.buf[len(header_buf):])
for p in &pixels { for &p in pixels {
p = u16be(transmute(u16) p) p = u16be(transmute(u16) p)
} }
} else if header.format in PFM { } else if header.format in PFM {
if header.little_endian { if header.little_endian {
pixels := mem.slice_data_cast([]f32le, data.buf[len(header_buf):]) pixels := mem.slice_data_cast([]f32le, data.buf[len(header_buf):])
for p in &pixels { for &p in pixels {
p = f32le(transmute(f32) p) p = f32le(transmute(f32) p)
} }
} else { } else {
pixels := mem.slice_data_cast([]f32be, data.buf[len(header_buf):]) pixels := mem.slice_data_cast([]f32be, data.buf[len(header_buf):])
for p in &pixels { for &p in pixels {
p = f32be(transmute(f32) p) p = f32be(transmute(f32) p)
} }
} }
@@ -578,18 +578,18 @@ decode_image :: proc(img: ^Image, header: Header, data: []byte, allocator := con
if header.format in PFM { if header.format in PFM {
pixels := mem.slice_data_cast([]f32, img.pixels.buf[:]) pixels := mem.slice_data_cast([]f32, img.pixels.buf[:])
if header.little_endian { if header.little_endian {
for p in &pixels { for &p in pixels {
p = f32(transmute(f32le) p) p = f32(transmute(f32le) p)
} }
} else { } else {
for p in &pixels { for &p in pixels {
p = f32(transmute(f32be) p) p = f32(transmute(f32be) p)
} }
} }
} else { } else {
if img.depth == 16 { if img.depth == 16 {
pixels := mem.slice_data_cast([]u16, img.pixels.buf[:]) pixels := mem.slice_data_cast([]u16, img.pixels.buf[:])
for p in &pixels { for &p in pixels {
p = u16(transmute(u16be) p) p = u16(transmute(u16be) p)
} }
} }
+1 -1
View File
@@ -36,7 +36,7 @@ destroy :: proc(img: ^Image) {
bytes.buffer_destroy(&img.pixels) bytes.buffer_destroy(&img.pixels)
if v, ok := img.metadata.(^image.PNG_Info); ok { if v, ok := img.metadata.(^image.PNG_Info); ok {
for chunk in &v.chunks { for chunk in v.chunks {
delete(chunk.data) delete(chunk.data)
} }
delete(v.chunks) delete(v.chunks)
+3 -3
View File
@@ -19,7 +19,7 @@ import rnd "core:math/rand"
int_destroy :: proc(integers: ..^Int) { int_destroy :: proc(integers: ..^Int) {
integers := integers integers := integers
for a in &integers { for a in integers {
assert_if_nil(a) assert_if_nil(a)
} }
#force_inline internal_int_destroy(..integers) #force_inline internal_int_destroy(..integers)
@@ -408,7 +408,7 @@ clear_if_uninitialized_multi :: proc(args: ..^Int, allocator := context.allocato
args := args args := args
assert_if_nil(..args) assert_if_nil(..args)
for i in &args { for i in args {
#force_inline internal_clear_if_uninitialized_single(i, allocator) or_return #force_inline internal_clear_if_uninitialized_single(i, allocator) or_return
} }
return err return err
@@ -435,7 +435,7 @@ int_init_multi :: proc(integers: ..^Int, allocator := context.allocator) -> (err
assert_if_nil(..integers) assert_if_nil(..integers)
integers := integers integers := integers
for a in &integers { for a in integers {
#force_inline internal_clear(a, true, allocator) or_return #force_inline internal_clear(a, true, allocator) or_return
} }
return nil return nil
+2 -2
View File
@@ -1857,7 +1857,7 @@ internal_root_n :: proc { internal_int_root_n, }
internal_int_destroy :: proc(integers: ..^Int) { internal_int_destroy :: proc(integers: ..^Int) {
integers := integers integers := integers
for a in &integers { for &a in integers {
if internal_int_allocated_cap(a) > 0 { if internal_int_allocated_cap(a) > 0 {
mem.zero_slice(a.digit[:]) mem.zero_slice(a.digit[:])
free(&a.digit[0]) free(&a.digit[0])
@@ -2909,7 +2909,7 @@ internal_int_init_multi :: proc(integers: ..^Int, allocator := context.allocator
context.allocator = allocator context.allocator = allocator
integers := integers integers := integers
for a in &integers { for a in integers {
internal_clear(a) or_return internal_clear(a) or_return
} }
return nil return nil
+1 -1
View File
@@ -137,7 +137,7 @@ rat_copy :: proc(dst, src: ^Rat, minimize := false, allocator := context.allocat
internal_rat_destroy :: proc(rationals: ..^Rat) { internal_rat_destroy :: proc(rationals: ..^Rat) {
rationals := rationals rationals := rationals
for z in &rationals { for &z in rationals {
internal_int_destroy(&z.a, &z.b) internal_int_destroy(&z.a, &z.b)
} }
} }
+1 -1
View File
@@ -450,7 +450,7 @@ flux_tween_init :: proc(tween: ^Flux_Tween($T), duration: time.Duration) where i
flux_update :: proc(flux: ^Flux_Map($T), dt: f64) where intrinsics.type_is_float(T) { flux_update :: proc(flux: ^Flux_Map($T), dt: f64) where intrinsics.type_is_float(T) {
clear(&flux.keys_to_be_deleted) clear(&flux.keys_to_be_deleted)
for key, tween in &flux.values { for key, &tween in flux.values {
delay_remainder := f64(0) delay_remainder := f64(0)
// Update delay if necessary. // Update delay if necessary.
+2 -2
View File
@@ -781,7 +781,7 @@ set_union_variant_raw_tag :: proc(a: any, tag: i64) {
tag_ptr := uintptr(a.data) + info.tag_offset tag_ptr := uintptr(a.data) + info.tag_offset
tag_any := any{rawptr(tag_ptr), info.tag_type.id} tag_any := any{rawptr(tag_ptr), info.tag_type.id}
switch i in &tag_any { switch &i in tag_any {
case u8: i = u8(tag) case u8: i = u8(tag)
case i8: i = i8(tag) case i8: i = i8(tag)
case u16: i = u16(tag) case u16: i = u16(tag)
@@ -1312,7 +1312,7 @@ relative_pointer_to_absolute_raw :: proc(data: rawptr, base_integer_id: typeid)
ptr_any := any{data, base_integer_id} ptr_any := any{data, base_integer_id}
ptr: rawptr ptr: rawptr
switch i in &ptr_any { switch &i in ptr_any {
case u8: ptr = _handle(&i) case u8: ptr = _handle(&i)
case u16: ptr = _handle(&i) case u16: ptr = _handle(&i)
case u32: ptr = _handle(&i) case u32: ptr = _handle(&i)
+4 -4
View File
@@ -1194,7 +1194,7 @@ Output:
split_lines :: proc(s: string, allocator := context.allocator) -> (res: []string, err: mem.Allocator_Error) #optional_allocator_error { split_lines :: proc(s: string, allocator := context.allocator) -> (res: []string, err: mem.Allocator_Error) #optional_allocator_error {
sep :: "\n" sep :: "\n"
lines := _split(s, sep, 0, -1, allocator) or_return lines := _split(s, sep, 0, -1, allocator) or_return
for line in &lines { for &line in lines {
line = _trim_cr(line) line = _trim_cr(line)
} }
return lines, nil return lines, nil
@@ -1234,7 +1234,7 @@ Output:
split_lines_n :: proc(s: string, n: int, allocator := context.allocator) -> (res: []string, err: mem.Allocator_Error) #optional_allocator_error { split_lines_n :: proc(s: string, n: int, allocator := context.allocator) -> (res: []string, err: mem.Allocator_Error) #optional_allocator_error {
sep :: "\n" sep :: "\n"
lines := _split(s, sep, 0, n, allocator) or_return lines := _split(s, sep, 0, n, allocator) or_return
for line in &lines { for &line in lines {
line = _trim_cr(line) line = _trim_cr(line)
} }
return lines, nil return lines, nil
@@ -1273,7 +1273,7 @@ Output:
split_lines_after :: proc(s: string, allocator := context.allocator) -> (res: []string, err: mem.Allocator_Error) #optional_allocator_error { split_lines_after :: proc(s: string, allocator := context.allocator) -> (res: []string, err: mem.Allocator_Error) #optional_allocator_error {
sep :: "\n" sep :: "\n"
lines := _split(s, sep, len(sep), -1, allocator) or_return lines := _split(s, sep, len(sep), -1, allocator) or_return
for line in &lines { for &line in lines {
line = _trim_cr(line) line = _trim_cr(line)
} }
return lines, nil return lines, nil
@@ -1314,7 +1314,7 @@ Output:
split_lines_after_n :: proc(s: string, n: int, allocator := context.allocator) -> (res: []string, err: mem.Allocator_Error) #optional_allocator_error { split_lines_after_n :: proc(s: string, n: int, allocator := context.allocator) -> (res: []string, err: mem.Allocator_Error) #optional_allocator_error {
sep :: "\n" sep :: "\n"
lines := _split(s, sep, len(sep), n, allocator) or_return lines := _split(s, sep, len(sep), n, allocator) or_return
for line in &lines { for &line in lines {
line = _trim_cr(line) line = _trim_cr(line)
} }
return lines, nil return lines, nil
+2 -2
View File
@@ -170,8 +170,8 @@ destroy :: proc(catalog: ^Translation = ACTIVE, allocator := context.allocator)
return return
} }
for section in &catalog.k_v { for section in catalog.k_v {
for key in &catalog.k_v[section] { for key in catalog.k_v[section] {
delete(catalog.k_v[section][key]) delete(catalog.k_v[section][key])
} }
delete(catalog.k_v[section]) delete(catalog.k_v[section])
+1 -1
View File
@@ -81,7 +81,7 @@ pool_destroy :: proc(pool: ^Pool) {
delete(pool.tasks) delete(pool.tasks)
delete(pool.tasks_done) delete(pool.tasks_done)
for t in &pool.threads { for &t in pool.threads {
destroy(t) destroy(t)
} }
@@ -221,7 +221,7 @@ named_xml_entity_to_rune :: proc(name: string) -> (decoded: rune, ok: bool) {
delete(entity_map) delete(entity_map)
delete(names) delete(names)
for name in &names { for &name in names {
free(&name) free(&name)
} }
} }