<commit_before>﻿using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace Pocket
{
    [DebuggerStepThrough]
    internal static class Disposable
    {
        private static readonly IDisposable empty = Create(() =>
        {
        });

        public static IDisposable Create(Action dispose) =>
            new AnonymousDisposable(dispose);

        public static IDisposable Empty { get; } = empty;

        private class AnonymousDisposable : IDisposable
        {
            private Action dispose;

            public AnonymousDisposable(Action dispose) =>
                this.dispose = dispose ??
                               throw new ArgumentNullException(nameof(dispose));

            public void Dispose()
            {
                dispose?.Invoke();
                dispose = null;
            }
        }
    }

    [DebuggerStepThrough]
    internal class CompositeDisposable : IDisposable, IEnumerable<IDisposable>
    {
        private bool isDisposed = false;
 
        private readonly List<IDisposable> disposables = new List<IDisposable>();

        public void Add(IDisposable disposable)
        {
            if (disposable == null)
            {
                throw new ArgumentNullException(nameof(disposable));
            }

            if (isDisposed)
            {
                disposable.Dispose();
            }

            disposables.Add(disposable);
        }

        public void Add(Action dispose) => Add(Disposable.Create(dispose));

        public void Dispose()
        {
            isDisposed = true;

            foreach (var disposable in disposables.ToArray())
            {
                disposables.Remove(disposable);
                disposable.Dispose();
            }
//
//            while (disposables.TryTake(out var disposable))
//            {
//                disposable.Dispose();
//            }
        }

        public IEnumerator<IDisposable> GetEnumerator() => disposables.GetEnumerator();<commit_msg>R: remove commented out code and unused using<commit_after>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace Pocket
{
    [DebuggerStepThrough]
    internal static class Disposable
    {
        private static readonly IDisposable empty = Create(() =>
        {
        });

        public static IDisposable Create(Action dispose) =>
            new AnonymousDisposable(dispose);

        public static IDisposable Empty { get; } = empty;

        private class AnonymousDisposable : IDisposable
        {
            private Action dispose;

            public AnonymousDisposable(Action dispose) =>
                this.dispose = dispose ??
                               throw new ArgumentNullException(nameof(dispose));

            public void Dispose()
            {
                dispose?.Invoke();
                dispose = null;
            }
        }
    }

    [DebuggerStepThrough]
    internal class CompositeDisposable : IDisposable, IEnumerable<IDisposable>
    {
        private bool isDisposed = false;
 
        private readonly List<IDisposable> disposables = new List<IDisposable>();

        public void Add(IDisposable disposable)
        {
            if (disposable == null)
            {
                throw new ArgumentNullException(nameof(disposable));
            }

            if (isDisposed)
            {
                disposable.Dispose();
            }

            disposables.Add(disposable);
        }

        public void Add(Action dispose) => Add(Disposable.Create(dispose));

        public void Dispose()
        {
            isDisposed = true;

            foreach (var disposable in disposables.ToArray())
            {
                disposables.Remove(disposable);
                disposable.Dispose();
            }
        }

        public IEnumerator<IDisposable> GetEnumerator() => disposables.GetEnumerator();
{'fraction_non_alphanumeric': 0.08230350963914977, 'fraction_numerical': 0.0, 'mean_word_length': 1.749320652173913, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, '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': '7559180', 'n_tokens_mistral': 1057, 'n_tokens_neox': 962, 'n_words': 229}