Skip to content

optimize array empty & avoid empty list creation in ctor#396

Open
lytico wants to merge 4 commits intoGtkSharp:developfrom
lytico:lytico/optimize_array_empty
Open

optimize array empty & avoid empty list creation in ctor#396
lytico wants to merge 4 commits intoGtkSharp:developfrom
lytico:lytico/optimize_array_empty

Conversation

@lytico
Copy link
Copy Markdown
Member

@lytico lytico commented Apr 6, 2023

replaced new[0] with array empty in non-generated code

in GapiCodegen/Ctor.cs:
if no fitting parameters found, use Array.Empty

Examples:

Before:

			if (GetType () != typeof (NoOpObject)) {
				var vals = new List<GLib.Value> ();
				var names = new List<string> ();
				CreateNativeObject (names.ToArray (), vals.ToArray ());
				return;
			}

After:

			if (GetType () != typeof (NoOpObject)) {
				CreateNativeObject (Array.Empty<string> (), Array.Empty<GLib.Value> ());
				return;
			}

if no nullable parameters found, use Array Initializer instead of list

Examples:

Before:

			if (GetType () != typeof (SimplePermission)) {
				var vals = new List<GLib.Value> ();
				var names = new List<string> ();
				names.Add ("allowed");
				vals.Add (new GLib.Value (allowed));
				CreateNativeObject (names.ToArray (), vals.ToArray ());
				return;
			}

after:

			if (GetType () != typeof (SimplePermission)) {
				CreateNativeObject (
				new[] {"allowed"},
				new[] {new GLib.Value (allowed)}
				);
				return;
			}

@lytico
Copy link
Copy Markdown
Member Author

lytico commented Apr 6, 2023

Build works, but

Pushing GdkSharp.3.24.24.85-develop.nupkg to 'https://nuget.pkg.github.com/GtkSharp'...
  PUT https://nuget.pkg.github.com/GtkSharp/
warn : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has 

fails

@lytico lytico closed this Apr 6, 2023
@lytico lytico reopened this Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant