mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-01 20:28:15 +00:00
Make the string type elements "immutable", akin to char const * in C
Allows for extra security and optimization benefits
This commit is contained in:
@@ -56,7 +56,7 @@ generic_ftoa :: proc(buf: []byte, val: f64, fmt: byte, precision, bit_size: int)
|
||||
} else {
|
||||
s = "+Inf";
|
||||
}
|
||||
n := copy(buf, cast([]byte)s);
|
||||
n := copy(buf, transmute([]byte)s);
|
||||
return buf[:n];
|
||||
|
||||
case 0: // denormalized
|
||||
|
||||
@@ -187,8 +187,8 @@ parse_f64 :: proc(s: string) -> f64 {
|
||||
|
||||
append_bool :: proc(buf: []byte, b: bool) -> string {
|
||||
n := 0;
|
||||
if b do n = copy(buf, cast([]byte)"true");
|
||||
else do n = copy(buf, cast([]byte)"false");
|
||||
if b do n = copy(buf, "true");
|
||||
else do n = copy(buf, "false");
|
||||
return string(buf[:n]);
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ quote_rune :: proc(buf: []byte, r: rune) -> string {
|
||||
}
|
||||
write_string :: inline proc(buf: []byte, i: ^int, s: string) {
|
||||
if i^ < len(buf) {
|
||||
n := copy(buf[i^:], cast([]byte)s);
|
||||
n := copy(buf[i^:], s);
|
||||
i^ += n;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user