Make the string type elements "immutable", akin to char const * in C

Allows for extra security and optimization benefits
This commit is contained in:
gingerBill
2019-12-01 14:10:59 +00:00
parent 7fbe0a6f23
commit 9db81498d8
25 changed files with 255 additions and 176 deletions
+1 -1
View File
@@ -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
+3 -3
View File
@@ -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;
}
}