Repository: dotnet/roslyn
File: src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingNamespaceSymbol.cs (C#)

Code before:

        internal override void GetExtensionMethods(ArrayBuilder<MethodSymbol> methods, string nameOpt, int arity, LookupOptions options)
        {
            var assembly = this.ContainingAssembly;

            // Only MergedNamespaceSymbol should have a null ContainingAssembly
            // and MergedNamespaceSymbol overrides GetExtensionMethods.
            Debug.Assert((object)assembly != null);

            if (!assembly.MightContainExtensionMethods)
            {
                return;
            }

            var underlyingMethods = ArrayBuilder<MethodSymbol>.GetInstance();
            _underlyingNamespace.GetExtensionMethods(underlyingMethods, nameOpt, arity, options);
            foreach (var underlyingMethod in underlyingMethods)
            {
                methods.Add(this.RetargetingTranslator.Retarget(underlyingMethod));
            }
            underlyingMethods.Free();
        }

        // Overridden to avoid NamespaceSymbol.GetExtensionMembers call to GetTypeMembersUnordered that
        // would cause a full array allocation.
        internal override void GetExtensionMembers(ArrayBuilder<Symbol> members, string name, string alternativeName, int arity, LookupOptions options, ConsList<FieldSymbol> fieldsBeingBound)
        {
            var assembly = this.ContainingAssembly;

            // Only MergedNamespaceSymbol should have a null ContainingAssembly
            // and MergedNamespaceSymbol overrides GetExtensionMembers.
            Debug.Assert((object)assembly != null);

            if (!assembly.MightContainExtensionMethods)
            {
                return;
            }

            var underlyingMembers = ArrayBuilder<Symbol>.GetInstance();
            _underlyingNamespace.GetExtensionMembers(underlyingMembers, name, alternativeName, arity, options, fieldsBeingBound);
            foreach (var underlyingMember in underlyingMembers)
            {
                members.Add(this.RetargetingTranslator.Retarget(underlyingMember));
            }

            underlyingMembers.Free();
        }

        internal sealed override CSharpCompilation DeclaringCompilation // perf, not correctness
        {
            get { return null; }

Review comment (performance):
:memo: I'm going to do one more test, since I've adjusted `NamespaceSymbol.GetExtensionsMembers` to use `TypesMightContainExtensionsMethods` (which is cached). We may not need this change after all. #Closed

Code after:

            if (underlying.IsExplicitDefinitionOfNoPiaLocalType)
            {
                // Explicitly defined local types should be hidden.
                return null;
            }

            return this.RetargetingTranslator.Retarget(underlying, RetargetOptions.RetargetPrimitiveTypesByName);
        }

#nullable disable

        internal override void GetExtensionMethods(ArrayBuilder<MethodSymbol> methods, string nameOpt, int arity, LookupOptions options)
        {
            var underlyingMethods = ArrayBuilder<MethodSymbol>.GetInstance();
            _underlyingNamespace.GetExtensionMethods(underlyingMethods, nameOpt, arity, options);
            foreach (var underlyingMethod in underlyingMethods)
            {
                methods.Add(this.RetargetingTranslator.Retarget(underlyingMethod));
            }
            underlyingMethods.Free();
        }

        internal sealed override CSharpCompilation DeclaringCompilation // perf, not correctness
        {
            get { return null; }
        }
    }
}