From 3892672d949e2b49224c9dcd8d089b2dd1c8727b Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Wed, 27 Jul 2022 09:43:47 -0400 Subject: [PATCH] [Mono.Android] Remove System.Linq usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: https://github.com/xamarin/xamarin-android/issues/5442 Remove all `using System.Linq` statements and all use of LINQ extension methods from `Mono.Android.dll`. Primary motivation was to reduce `.apk` size (09baa52e), and we don't want to inadvertently allow LINQ usage back in… --- src/Mono.Android/Android.Graphics/Color.cs | 1 - src/Mono.Android/Android.Runtime/AndroidEnvironment.cs | 1 - src/Mono.Android/Android.Runtime/AndroidRuntime.cs | 1 - src/Mono.Android/Android.Runtime/CharSequence.cs | 1 - .../Android.Runtime/IJavaObjectValueMarshaler.cs | 1 - src/Mono.Android/Android.Runtime/JNIEnv.cs | 2 -- src/Mono.Android/Android.Runtime/JavaArray.cs | 5 +++-- 7 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Mono.Android/Android.Graphics/Color.cs b/src/Mono.Android/Android.Graphics/Color.cs index 20c43e1e7dc..44cb881a97c 100644 --- a/src/Mono.Android/Android.Graphics/Color.cs +++ b/src/Mono.Android/Android.Graphics/Color.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Text; diff --git a/src/Mono.Android/Android.Runtime/AndroidEnvironment.cs b/src/Mono.Android/Android.Runtime/AndroidEnvironment.cs index ce06de843c3..d4828cd28b1 100644 --- a/src/Mono.Android/Android.Runtime/AndroidEnvironment.cs +++ b/src/Mono.Android/Android.Runtime/AndroidEnvironment.cs @@ -2,7 +2,6 @@ using System.Net; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Net.Security; using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; diff --git a/src/Mono.Android/Android.Runtime/AndroidRuntime.cs b/src/Mono.Android/Android.Runtime/AndroidRuntime.cs index aaa8823deed..74b08e63670 100644 --- a/src/Mono.Android/Android.Runtime/AndroidRuntime.cs +++ b/src/Mono.Android/Android.Runtime/AndroidRuntime.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; diff --git a/src/Mono.Android/Android.Runtime/CharSequence.cs b/src/Mono.Android/Android.Runtime/CharSequence.cs index 92ac57b687e..fc0012de93c 100644 --- a/src/Mono.Android/Android.Runtime/CharSequence.cs +++ b/src/Mono.Android/Android.Runtime/CharSequence.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; diff --git a/src/Mono.Android/Android.Runtime/IJavaObjectValueMarshaler.cs b/src/Mono.Android/Android.Runtime/IJavaObjectValueMarshaler.cs index 99237aaa223..f5cab61ec1d 100644 --- a/src/Mono.Android/Android.Runtime/IJavaObjectValueMarshaler.cs +++ b/src/Mono.Android/Android.Runtime/IJavaObjectValueMarshaler.cs @@ -1,6 +1,5 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Linq.Expressions; using System.Reflection; diff --git a/src/Mono.Android/Android.Runtime/JNIEnv.cs b/src/Mono.Android/Android.Runtime/JNIEnv.cs index 36c2e476340..26485b9462a 100644 --- a/src/Mono.Android/Android.Runtime/JNIEnv.cs +++ b/src/Mono.Android/Android.Runtime/JNIEnv.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; -using System.Linq.Expressions; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; diff --git a/src/Mono.Android/Android.Runtime/JavaArray.cs b/src/Mono.Android/Android.Runtime/JavaArray.cs index b5de4ac1d04..4d05a7de4a3 100644 --- a/src/Mono.Android/Android.Runtime/JavaArray.cs +++ b/src/Mono.Android/Android.Runtime/JavaArray.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Linq; namespace Android.Runtime { @@ -108,7 +107,9 @@ public static IntPtr ToLocalJniHandle (IList? value) if (c != null) return JNIEnv.ToLocalJniHandle (c); - var a = value.ToArray (); + var a = new T [value.Count]; + value.CopyTo (a, 0); + return JNIEnv.NewArray (a, typeof (T)); } }