Skip to content

Commit

Permalink
Review update
Browse files Browse the repository at this point in the history
  • Loading branch information
lcodes committed Oct 25, 2024
1 parent bfb7791 commit 70d929c
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions crates/cli/src/subcommands/generate/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,10 @@ fn autogen_csharp_access_funcs_for_struct(
};
writeln!(
output,
"public readonly ref struct {csharp_field_name_pascal}UniqueIndex"
"public class {csharp_field_name_pascal}UniqueIndex"
);
indented_block(output, |output| {
writeln!(output, "readonly {csharp_table_name}Handle Handle;");
write!(
output,
"internal {csharp_field_name_pascal}UniqueIndex({csharp_table_name}Handle handle) => "
);
writeln!(output, "Handle = handle;");
write!(output, "internal readonly Dictionary<{csharp_field_type}, {csharp_table_name}> __Cache = new(16);");
writeln!(output);

writeln!(
Expand All @@ -427,7 +422,7 @@ fn autogen_csharp_access_funcs_for_struct(
indented_block(output, |output| {
writeln!(
output,
"Handle.{csharp_field_name_pascal}_Index.TryGetValue(value, out var r);"
"__Cache.TryGetValue(value, out var r);"
);
writeln!(output, "return r;");
});
Expand All @@ -436,7 +431,7 @@ fn autogen_csharp_access_funcs_for_struct(
writeln!(output);
writeln!(
output,
"public {csharp_field_name_pascal}UniqueIndex {csharp_field_name_pascal} => new(this);"
"public {csharp_field_name_pascal}UniqueIndex {csharp_field_name_pascal} = new();"
);
writeln!(output);
}
Expand Down Expand Up @@ -597,11 +592,6 @@ pub fn autogen_csharp_globals(ctx: &GenCtx, items: &[GenItem], namespace: &str)
if !constraints[&ColList::new(col.col_pos)].has_unique() {
continue;
}
let type_name = ty_fmt(ctx, &col.col_type, namespace);
writeln!(
output,
"private Dictionary<{type_name}, {table_type}> {field_name}_Index = new(16);"
);
unique_indexes.push(field_name);
}
if !unique_indexes.is_empty() {
Expand All @@ -618,7 +608,7 @@ pub fn autogen_csharp_globals(ctx: &GenCtx, items: &[GenItem], namespace: &str)
if !constraints[&ColList::new(col.col_pos)].has_unique() {
continue;
}
writeln!(output, "{field_name}_Index[value.{field_name}] = value;");
writeln!(output, "{field_name}.__Cache[value.{field_name}] = value;");
}
});
writeln!(output);
Expand All @@ -633,7 +623,7 @@ pub fn autogen_csharp_globals(ctx: &GenCtx, items: &[GenItem], namespace: &str)
if !constraints[&ColList::new(col.col_pos)].has_unique() {
continue;
}
writeln!(output, "{field_name}_Index.Remove((({table_type})row).{field_name});");
writeln!(output, "{field_name}.__Cache.Remove((({table_type})row).{field_name});");
}
});
writeln!(output);
Expand Down

0 comments on commit 70d929c

Please sign in to comment.