GtkSharp icon indicating copy to clipboard operation
GtkSharp copied to clipboard

optimize array empty & avoid empty list creation in ctor

Open lytico opened this issue 1 year ago • 1 comments

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 avatar Apr 06 '23 20:04 lytico