Remove internal `Xamarin.Utils.*` types from platform assemblies (#11811)

Only the `SanitizeObjectiveCName` method _can_ be needed, by the
registrar. However if marked then the `StringUtils:.cctor` will also be
marked, including the data (`static char[]`) which is not needed for apps

Moving `SanitizeObjectiveCName` to the `Registrar` type is simpler and
solve (removes) the extra cost (baggage) from the app.
This commit is contained in:
Sebastien Pouliot 2021-06-04 09:12:59 -04:00 коммит произвёл GitHub
Родитель fd500dc53c
Коммит 0de6274cb7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 39 добавлений и 39 удалений

Просмотреть файл

@ -1,3 +1,4 @@
using System.Text;
namespace Registrar {
abstract partial class Registrar {
@ -12,5 +13,38 @@ namespace Registrar {
first = (char) (first - 32 /* 'a' - 'A' */);
return "set" + ((char) first).ToString () + getterSelector.Substring (1) + ":";
}
public static string SanitizeObjectiveCName (string name)
{
StringBuilder sb = null;
for (int i = 0; i < name.Length; i++) {
var ch = name [i];
switch (ch) {
case '.':
case '+':
case '/':
case '`':
case '@':
case '<':
case '>':
case '$':
case '-':
if (sb == null)
sb = new StringBuilder (name, 0, i, name.Length);
sb.Append ('_');
break;
default:
if (sb != null)
sb.Append (ch);
break;
}
}
if (sb != null)
return sb.ToString ();
return name;
}
}
}

Просмотреть файл

@ -22,10 +22,10 @@ using System.Text;
using Foundation;
using ObjCRuntime;
using Xamarin.Utils;
using Xamarin.Bundler;
#if MTOUCH || MMP || BUNDLER
using Xamarin.Utils;
using TAssembly=Mono.Cecil.AssemblyDefinition;
using TType=Mono.Cecil.TypeReference;
using TMethod=Mono.Cecil.MethodDefinition;
@ -437,7 +437,7 @@ namespace Registrar {
throw new InvalidOperationException ();
var attrib = CategoryAttribute;
var name = attrib.Name ?? Registrar.GetTypeFullName (Type);
return StringUtils.SanitizeObjectiveCName (name);
return SanitizeObjectiveCName (name);
}
}
@ -447,7 +447,7 @@ namespace Registrar {
throw new InvalidOperationException ();
var attrib = Registrar.GetProtocolAttribute (Type);
var name = attrib.Name ?? Registrar.GetTypeFullName (Type);
return StringUtils.SanitizeObjectiveCName (name);
return SanitizeObjectiveCName (name);
}
}
@ -2600,7 +2600,7 @@ namespace Registrar {
}
if (name == null)
name = GetTypeFullName (type);
return StringUtils.SanitizeObjectiveCName (name);
return SanitizeObjectiveCName (name);
}
protected string GetExportedTypeName (TType type)

Просмотреть файл

@ -1842,7 +1842,6 @@ SHARED_CORE_SOURCES = \
SHARED_SOURCES = \
../runtime/Delegates.generated.cs \
../tools/common/StringUtils.cs \
MonoNativeFunctionWrapperAttribute.cs \
NativeTypes/NMath.cs \
ObjCRuntime/AdoptsAttribute.cs \

Просмотреть файл

@ -6412,7 +6412,7 @@ public partial class Generator : IMemberGatherer {
if (!string.IsNullOrEmpty (model.Name)) {
register_name = model.Name;
} else if (model.AutoGeneratedName) {
register_name = StringUtils.SanitizeObjectiveCName (GetAssemblyName () + "__" + type.FullName);
register_name = Registrar.Registrar.SanitizeObjectiveCName (GetAssemblyName () + "__" + type.FullName);
}
}
Header (sw);

Просмотреть файл

@ -221,39 +221,6 @@ namespace Xamarin.Utils {
return new Version (major, 0);
return Version.Parse (v);
}
public static string SanitizeObjectiveCName (string name)
{
StringBuilder sb = null;
for (int i = 0; i < name.Length; i++) {
var ch = name [i];
switch (ch) {
case '.':
case '+':
case '/':
case '`':
case '@':
case '<':
case '>':
case '$':
case '-':
if (sb == null)
sb = new StringBuilder (name, 0, i, name.Length);
sb.Append ('_');
break;
default:
if (sb != null)
sb.Append (ch);
break;
}
}
if (sb != null)
return sb.ToString ();
return name;
}
}
static class StringExtensions