Null annotations and in string args#142
Conversation
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://ambitious-hill-0f19b7c03-142.westeurope.azurestaticapps.net |
|
This is cool, but what do you think about |
|
@SupinePandora43 I like the idea about |
SupinePandora43
left a comment
There was a problem hiding this comment.
I haven't been active lately (in general), I'll try to fix that
| public override void Write(string? value) | ||
| { | ||
| if (!String.IsNullOrEmpty(value)) | ||
| if (!String.IsNullOrEmpty(value) && Msg is not null) |
There was a problem hiding this comment.
I think this is redundant
There was a problem hiding this comment.
Maybe, but C# null checker is not satisfied otherwise.
|
|
||
| public int Top() | ||
| { | ||
| if (top is null) |
There was a problem hiding this comment.
Can we not check it every call? Or is it eliminated by JIT?
There was a problem hiding this comment.
JIT will eliminate checks after few iterations
There was a problem hiding this comment.
I think we should check it. (Performance regressions)
There was a problem hiding this comment.
Even if it is not optimized, here is an result with check (https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBDAzgWwB8ABAJgEYBYAKGIGYACMhgYQYG8aHunGBLAHYYGAWQAUxAKwAeQRjQM5APgYATGABsAlBy499fAGYMx6jYtwMBAVw3a9+7p2qPXDDAAsoEAO5WYfgCiCGAwAA4YfBACYloA3A6OAL6J+qk8xADsappikvGJKdRJQA===) and without (https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBDAzgWwB8ABAJgEYBYAKGIGYACMhgYQYG8aHunGBLAHYYGAWQAUxAKwAeQRjQM5APgYATGABsAlBy499xAOxrNYyVoDce7gF8aNoA==). Check is just +15 CPU instructions. It is noise.
| IModule current_module = (IModule)Activator.CreateInstance(t); | ||
| modules.Add(current_module); | ||
| gc_handles.Add(GCHandle.Alloc(current_module)); | ||
| IModule? current_module = Activator.CreateInstance(t) as IModule; |
There was a problem hiding this comment.
CreateInstance has null annotation on return type: https://learn.microsoft.com/en-us/dotnet/api/system.activator.createinstance?view=net-7.0#system-activator-createinstance(system-type)
There was a problem hiding this comment.
Can you add ! somewhere to make it not nullable? 😅
There was a problem hiding this comment.
But why? We literally check if it is null in a next line. Let it be this way until Microsoft provide non-nulable guaranties for Activator (so until .NET 8, maybe?).
I'll create few feature requests issues with ideas i came up with. |
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://ambitious-hill-0f19b7c03-142.westeurope.azurestaticapps.net |
Removes redundant
in stringparameters from the API surface and enables nullable annotations and nullable warnings as errorsfor both GmodNET.API and core GmodNET.
Closes #141
Closes #84