<commit_before>﻿using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace Log4JParserNet
{
    internal sealed class FilteredEventSource
        : IEnumerable<Event>
        , IEventSource
    {
        private sealed class Enumerator : EnumeratorBase
        {
            public Enumerator (EnumeratorBase inner, FilterBase filter)
                : base (Init (inner.Handle, filter.Handle), inner.Owner)
            {

            }

            private static IteratorHandle Init (IteratorHandle inner, FilterHandle filter)
            {
                IteratorHandle result;
                Log4JParserC.Log4JIteratorInitFilter (out result, inner, filter);

                return result;
            }
        }

        private readonly IEventSource source_;

        private readonly FilterBase filter_;

        SafeHandle IEventSource.Owner
        {
            get { return source_.Owner; }
        }

        public FilteredEventSource (IEventSource source, FilterBase filter)
        {
            Debug.Assert (source != null, "FilteredEventSource.ctor: source is null.");
            Debug.Assert (filter != null, "FilteredEventSource.ctor: filter is null.");

            source_ = source;
            filter_ = filter;
        }

        internal EnumeratorBase GetEnumerator ()
        {
            return new Enumerator (source_.GetEnumerator (), filter_);
        }

        EnumeratorBase IEventSource.GetEnumerator ()
        {<commit_msg>Fixed FilteredEventSource enumerator not holding reference to the wrapped enumerator exposing it to early finalization.<commit_after>﻿using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace Log4JParserNet
{
    internal sealed class FilteredEventSource
        : IEnumerable<Event>
        , IEventSource
    {
        private sealed class Enumerator : EnumeratorBase
        {
            private readonly EnumeratorBase inner_;

            public Enumerator (EnumeratorBase inner, FilterBase filter)
                : base (Init (inner.Handle, filter.Handle), inner.Owner)
            {
                inner_ = inner;
            }

            private static IteratorHandle Init (IteratorHandle inner, FilterHandle filter)
            {
                IteratorHandle result;
                Log4JParserC.Log4JIteratorInitFilter (out result, inner, filter);

                return result;
            }

            protected override void Dispose (bool disposing)
            {
                if (disposing)
                {
                    inner_.Dispose ();
                }
                base.Dispose (disposing);
            }
        }

        private readonly IEventSource source_;

        private readonly FilterBase filter_;

        SafeHandle IEventSource.Owner
        {
            get { return source_.Owner; }
        }

        public FilteredEventSource (IEventSource source, FilterBase filter)
        {
            Debug.Assert (source != null, "FilteredEventSource.ctor: source is null.");
            Debug.Assert (filter != null, "FilteredEventSource.ctor: filter is null.");

            source_ = source;
            filter_ = filter;
        }

        internal EnumeratorBase GetEnumerator ()
        {
            return new Enumerator (source_.GetEnumerator (), filter_);
        }

        EnumeratorBase IEventSource.GetEnumerator ()
        {
{'fraction_non_alphanumeric': 0.06723646723646724, 'fraction_numerical': 0.0017094017094017094, 'mean_word_length': 1.8825944170771758, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6876263', 'n_tokens_mistral': 852, 'n_tokens_neox': 821, 'n_words': 223}