Repository: dotnet/runtime
File: src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs (C#)

Code before:
                    // for mangling, otherwise we use the mangling of the type and its generic type
                    // parameters, e.g. A <B> becomes A_<___B_>_.
                    var typeDefinition = type.GetTypeDefinition();
                    if (typeDefinition != type)
                    {
                        var sb = new Utf8StringBuilder();
                        sb.Append(GetMangledTypeName(typeDefinition));

                        var inst = type.Instantiation;
                        sb.Append(EnterNameScopeSequence);
                        for (int i = 0; i < inst.Length; i++)
                        {
                            if (i > 0)
                                sb.Append("__"u8);
                            sb.Append(GetMangledTypeName(inst[i]));
                        }
                        sb.Append(ExitNameScopeSequence);
                        mangledName = sb.ToUtf8String();
                    }
                    else if (type is IPrefixMangledMethod)
                    {
                        mangledName = new Utf8String(GetPrefixMangledMethodName((IPrefixMangledMethod)type).ToString());
                    }
                    else if (type is IPrefixMangledType)
                    {
                        mangledName = new Utf8String(GetPrefixMangledTypeName((IPrefixMangledType)type).ToString());
                    }
                    else
                    {
                        // This is a type definition. Since we didn't fall in the `is EcmaType` case above,
                        // it's likely a compiler-generated type.
                        mangledName = new Utf8String(SanitizeName(((DefType)type).GetFullName()));
                    }
                    break;
            }

            lock (this)
            {
                // Ensure that name is unique and update our tables accordingly.
                _mangledTypeNames.TryAdd(type, mangledName);
            }

            return mangledName;
        }

        private Dictionary<MethodDesc, Utf8String> _mangledMethodNames = new Dictionary<MethodDesc, Utf8String>();
        private Dictionary<MethodDesc, Utf8String> _unqualifiedMangledMethodNames = new Dictionary<MethodDesc, Utf8String>();

        public override Utf8String GetMangledMethodName(MethodDesc method)
        {
            Utf8String utf8MangledName;

Review comment (suggestion):
`GetPrefixMangledTypeName` returns Utf8String. This roundtrip via String is unnecessary

Code after:
                        .Append(EnterNameScopeSequence).Append("ByRef"u8).Append(ExitNameScopeSequence).ToUtf8String();
                    break;
                case TypeFlags.Pointer:
                    mangledName = new Utf8StringBuilder()
                        .Append(GetMangledTypeName(((PointerType)type).ParameterType))
                        .Append(EnterNameScopeSequence).Append("Pointer"u8).Append(ExitNameScopeSequence).ToUtf8String();
                    break;
                case TypeFlags.FunctionPointer:
                {
                    var fnPtrType = (FunctionPointerType)type;
                    var sb = new Utf8StringBuilder();
                    sb.Append("__FnPtr_"u8).Append(((int)fnPtrType.Signature.Flags).ToString("X2")).Append(EnterNameScopeSequence);
                    sb.Append(GetMangledTypeName(fnPtrType.Signature.ReturnType));

                    sb.Append(EnterNameScopeSequence);
                    for (int i = 0; i < fnPtrType.Signature.Length; i++)
                    {
                        if (i != 0)
                            sb.Append(DelimitNameScopeSequence);
                        sb.Append(GetMangledTypeName(fnPtrType.Signature[i]));
                    }
                    sb.Append(ExitNameScopeSequence);

                    sb.Append(ExitNameScopeSequence);
                    mangledName = sb.ToUtf8String();
                    break;
                }
                default:
                    // Case of a generic type. If `type' is a type definition we use the type name
                    // for mangling, otherwise we use the mangling of the type and its generic type
                    // parameters, e.g. A <B> becomes A_<___B_>_.
                    var typeDefinition = type.GetTypeDefinition();
                    if (typeDefinition != type)
                    {
                        var sb = new Utf8StringBuilder();
                        sb.Append(GetMangledTypeName(typeDefinition));

                        var inst = type.Instantiation;
                        sb.Append(EnterNameScopeSequence);
                        for (int i = 0; i < inst.Length; i++)
                        {
                            if (i > 0)
                                sb.Append("__"u8);
                            sb.Append(GetMangledTypeName(inst[i]));
                        }
                        sb.Append(ExitNameScopeSequence);
                        mangledName = sb.ToUtf8String();
                    }
                    else if (type is IPrefixMangledMethod)
                    {
                        mangledName = GetPrefixMangledMethodName((IPrefixMangledMethod)type);