<commit_before>namespace AgileObjects.AgileMapper.Members
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Linq.Expressions;
    using Extensions;
    using ReadableExpressions;

    internal class ConfiguredSourceMember : IQualifiedMember
    {
        private readonly string[] _matchedTargetMemberNames;
        private readonly IEnumerable<string> _matchedTargetMemberJoinedNames;
        private readonly NamingSettings _namingSettings;
        private readonly Member[] _childMembers;

        public ConfiguredSourceMember(Expression value, MemberMapperData data)
            : this(
                  value.Type,
                  value.Type.IsEnumerable(),
                  value.ToReadableString(),
                  data.TargetMember.MemberChain.Select(data.MapperContext.NamingSettings.GetMatchingNameFor).ToArray(),
                  data.MapperContext.NamingSettings)
        {
        }

        private ConfiguredSourceMember(ConfiguredSourceMember parent, Member childMember, bool isEnumerable)
            : this(
                  childMember.Type,
                  isEnumerable,
                  parent.Name + childMember.JoiningName,
                  parent._matchedTargetMemberNames.Append(parent._namingSettings.GetMatchingNameFor(childMember)),
                  parent._namingSettings,
                  parent._childMembers.Append(childMember))
        {
        }

        private ConfiguredSourceMember(
            Type type,
            bool isEnumerable,
            string name,
            string[] matchedTargetMemberNames,
            NamingSettings namingSettings,
            Member[] childMembers = null)
            : this(
                  type, 
                  isEnumerable, 
                  name, 
                  matchedTargetMemberNames, 
                  namingSettings.GetJoinedNamesFor(matchedTargetMemberNames), 
                  namingSettings, 
                  childMembers)
        {
        }

        private ConfiguredSourceMember(
            Type type,
            bool isEnumerable,
            string name,
            string[] matchedTargetMemberNames,
            IEnumerable<string> matchedTargetMemberJoinedNames,
            NamingSettings namingSettings,
            Member[] childMembers = null)
        {
            Type = type;
            IsEnumerable = isEnumerable;
            Name = name;
            _matchedTargetMemberNames = matchedTargetMemberNames;
            _matchedTargetMemberJoinedNames = matchedTargetMemberJoinedNames;
            _namingSettings = namingSettings;
            _childMembers = childMembers ?? new[] { Member.RootSource(name, type) };
            Signature = _childMembers.GetSignature();
        }

        public Type Type { get; }

        public bool IsEnumerable { get; }

        public string Name { get; }

        public string Signature { get; }

        public string GetPath() => _childMembers.GetFullName();

        public IQualifiedMember Append(Member childMember) => new ConfiguredSourceMember(this, childMember, IsEnumerable);

        public IQualifiedMember RelativeTo(IQualifiedMember otherMember)
        {
            var otherConfiguredMember = (ConfiguredSourceMember)otherMember;
            var relativeMemberChain = _childMembers.RelativeTo(otherConfiguredMember._childMembers);

            return new ConfiguredSourceMember(
                Type,
                IsEnumerable,
                Name,
                _matchedTargetMemberNames,
                _matchedTargetMemberJoinedNames,
                _namingSettings,
                relativeMemberChain);<commit_msg>Caching configured source member child members<commit_after>namespace AgileObjects.AgileMapper.Members
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Linq.Expressions;
    using Caching;
    using Extensions;
    using ReadableExpressions;

    internal class ConfiguredSourceMember : IQualifiedMember
    {
        private readonly string[] _matchedTargetMemberNames;
        private readonly IEnumerable<string> _matchedTargetMemberJoinedNames;
        private readonly MapperContext _mapperContext;
        private readonly Member[] _childMembers;
        private readonly ICache<string, ConfiguredSourceMember> _childMemberCache;

        public ConfiguredSourceMember(Expression value, MemberMapperData data)
            : this(
                  value.Type,
                  value.Type.IsEnumerable(),
                  value.ToReadableString(),
                  data.TargetMember.MemberChain.Select(data.MapperContext.NamingSettings.GetMatchingNameFor).ToArray(),
                  data.MapperContext)
        {
        }

        private ConfiguredSourceMember(ConfiguredSourceMember parent, Member childMember, bool isEnumerable)
            : this(
                  childMember.Type,
                  isEnumerable,
                  parent.Name + childMember.JoiningName,
                  parent._matchedTargetMemberNames.Append(
                      parent._mapperContext.NamingSettings.GetMatchingNameFor(childMember)),
                  parent._mapperContext,
                  parent._childMembers.Append(childMember))
        {
        }

        private ConfiguredSourceMember(
            Type type,
            bool isEnumerable,
            string name,
            string[] matchedTargetMemberNames,
            MapperContext mapperContext,
            Member[] childMembers = null)
            : this(
                  type,
                  isEnumerable,
                  name,
                  matchedTargetMemberNames,
                  mapperContext.NamingSettings.GetJoinedNamesFor(matchedTargetMemberNames),
                  mapperContext,
                  childMembers)
        {
        }

        private ConfiguredSourceMember(
            Type type,
            bool isEnumerable,
            string name,
            string[] matchedTargetMemberNames,
            IEnumerable<string> matchedTargetMemberJoinedNames,
            MapperContext mapperContext,
            Member[] childMembers = null)
        {
            Type = type;
            IsEnumerable = isEnumerable;
            Name = name;
            _matchedTargetMemberNames = matchedTargetMemberNames;
            _matchedTargetMemberJoinedNames = matchedTargetMemberJoinedNames;
            _mapperContext = mapperContext;
            _childMembers = childMembers ?? new[] { Member.RootSource(name, type) };
            Signature = _childMembers.GetSignature();
            _childMemberCache = mapperContext.Cache.CreateNew<string, ConfiguredSourceMember>();
        }

        public Type Type { get; }

        public bool IsEnumerable { get; }

        public string Name { get; }

        public string Signature { get; }

        public string GetPath() => _childMembers.GetFullName();

        public IQualifiedMember Append(Member childMember)
        {
            var key = childMember.IsSimple ? childMember.Name : childMember.Signature;

            return _childMemberCache.GetOrAdd(key, n => new ConfiguredSourceMember(this, childMember, IsEnumerable));
        }

        public IQualifiedMember RelativeTo(IQualifiedMember otherMember)
        {
            var otherConfiguredMember = (ConfiguredSourceMember)otherMember;
            var relativeMemberChain = _childMembers.RelativeTo(otherConfiguredMember._childMembers);

            return new ConfiguredSourceMember(
                Type,
                IsEnumerable,
                Name,
                _matchedTargetMemberNames,
                _matchedTargetMemberJoinedNames,
                _mapperContext,
                relativeMemberChain);
{'fraction_non_alphanumeric': 0.059331871533599895, 'fraction_numerical': 0.0, 'mean_word_length': 1.9697433933358865, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3304154', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1695, 'n_words': 357}