From bee4f257c73402dcd0ce475d0887bdc625382d0c Mon Sep 17 00:00:00 2001 From: Raphael Luba Date: Tue, 2 Jan 2024 11:00:16 +0100 Subject: [PATCH] Improved stupidly slow enum name normalization --- examples/example.jai | 2 +- typed.jai | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/example.jai b/examples/example.jai index 920e53e..aa827e4 100644 --- a/examples/example.jai +++ b/examples/example.jai @@ -54,7 +54,7 @@ Entity :: struct { LEVEL_DATA_1_JSON := #string DONE -{"kind": ".HARD", "flags": ".FLAG_A | .FLAG_C", "secret": false,"score":5.5,"player": {"name": "Pat","x": 10,"y": 10},"player2": {"name": "Chris"},"entities": [{"name": "fdsa","x": 0,"y": 0},{"name": "fdsa","x": 0,"y": 0}], "floats": [0.00, 1.11111111111111111, 2.0202, 3e-5, 4.444444, -5.0]} +{"kind": ".HARD", "flags": "FLAG_A | LevelFlags.FLAG_C", "secret": false,"score":5.5,"player": {"name": "Pat","x": 10,"y": 10},"player2": {"name": "Chris"},"entities": [{"name": "fdsa","x": 0,"y": 0},{"name": "fdsa","x": 0,"y": 0}], "floats": [0.00, 1.11111111111111111, 2.0202, 3e-5, 4.444444, -5.0]} DONE; LEVEL_DATA_2_JSON := #string DONE diff --git a/typed.jai b/typed.jai index d396a86..e40a3fb 100644 --- a/typed.jai +++ b/typed.jai @@ -369,11 +369,11 @@ parse_enum_string :: (str: string, slot: *u8, info_enum: *Type_Info_Enum) -> rem // Parse by members' names normalize_enum_value :: inline (name: string) -> string #expand { normalized := trim(name); - // @Speed, @Cleanup: Why are we tprinting this every time? We could just use the name directly and then check for the dot. - if starts_with(normalized, tprint("%.", info_enum.name)) + if normalized.count > info_enum.name.count && starts_with(normalized, info_enum.name) && normalized[info_enum.name.count] == #char "." { normalized = slice(normalized, info_enum.name.count+1, normalized.count-info_enum.name.count-1); - if starts_with(normalized, ".") + } else if starts_with(normalized, ".") { normalized = slice(normalized, 1, normalized.count-1); + } return normalized; } @@ -395,8 +395,8 @@ parse_enum_string :: (str: string, slot: *u8, info_enum: *Type_Info_Enum) -> rem if !found_name { log_error("Enum \"%\" does not contain a member named \"%\".", info_enum.name, name); - success = false; - } + success = false; + } } } else { success = false;