diff options
| author | gingerBill <bill@gingerbill.org> | 2019-12-01 14:10:59 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2019-12-01 14:10:59 +0000 |
| commit | 9db81498d8fbf4b24383cd7de94619943ad4e01a (patch) | |
| tree | 6263d1649607f44a1d8affc2baf1d39da906698f /core/encoding | |
| parent | 7fbe0a6f2385e618ea4d3a724d2ed6147b6921bf (diff) | |
Make the `string` type elements "immutable", akin to `char const *` in C
Allows for extra security and optimization benefits
Diffstat (limited to 'core/encoding')
| -rw-r--r-- | core/encoding/cel/cel.odin | 6 | ||||
| -rw-r--r-- | core/encoding/json/marshal.odin | 14 | ||||
| -rw-r--r-- | core/encoding/json/parser.odin | 4 |
3 files changed, 12 insertions, 12 deletions
diff --git a/core/encoding/cel/cel.odin b/core/encoding/cel/cel.odin index 754d8cbfa..fe36978c2 100644 --- a/core/encoding/cel/cel.odin +++ b/core/encoding/cel/cel.odin @@ -91,7 +91,7 @@ print :: proc(p: ^Parser, pretty := false) { } create_from_string :: proc(src: string) -> (^Parser, bool) { - return init(cast([]byte)src); + return init(transmute([]byte)src); } @@ -726,8 +726,8 @@ calculate_binary_value :: proc(p: ^Parser, op: Kind, a, b: Value) -> (Value, boo case Kind.Add: n := len(a) + len(b); data := make([]byte, n); - copy(data[:], cast([]byte)a); - copy(data[len(a):], cast([]byte)b); + copy(data[:], a); + copy(data[len(a):], b); s := string(data); append(&p.allocated_strings, s); return s, true; diff --git a/core/encoding/json/marshal.odin b/core/encoding/json/marshal.odin index 60839b21b..f3d894f3f 100644 --- a/core/encoding/json/marshal.odin +++ b/core/encoding/json/marshal.odin @@ -95,17 +95,17 @@ marshal_arg :: proc(b: ^strings.Builder, v: any) -> Marshal_Error { buf: [386]byte; str := strconv.append_float(buf[1:], val, 'f', 2*ti.size, 8*ti.size); - str = string(buf[:len(str)+1]); - if str[1] == '+' || str[1] == '-' { - str = str[1:]; + s := buf[:len(str)+1]; + if s[1] == '+' || s[1] == '-' { + s = s[1:]; } else { - str[0] = '+'; + s[0] = '+'; } - if str[0] == '+' { - str = str[1:]; + if s[0] == '+' { + s = s[1:]; } - write_string(b, str); + write_string(b, string(s)); case Type_Info_Complex: return Marshal_Error.Unsupported_Type; diff --git a/core/encoding/json/parser.odin b/core/encoding/json/parser.odin index 63f4a758b..36a68f31c 100644 --- a/core/encoding/json/parser.odin +++ b/core/encoding/json/parser.odin @@ -174,7 +174,7 @@ parse_array :: proc(p: ^Parser) -> (value: Value, err: Error) { clone_string :: proc(s: string, allocator: mem.Allocator) -> string { n := len(s); b := make([]byte, n+1, allocator); - copy(b, cast([]byte)s); + copy(b, s); b[n] = 0; return string(b[:n]); } @@ -349,7 +349,7 @@ unquote_string :: proc(token: Token, spec: Specification, allocator := context.a } b := make([]byte, len(s) + 2*utf8.UTF_MAX, allocator); - w := copy(b, cast([]byte)s[0:i]); + w := copy(b, s[0:i]); loop: for i < len(s) { c := s[i]; switch { |