Skip to content

Commit

Permalink
Improved stupidly slow enum name normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
rluba committed Jan 2, 2024
1 parent 6a29ec2 commit bee4f25
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/example.jai
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions typed.jai
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down

0 comments on commit bee4f25

Please sign in to comment.