<commit_before>﻿// Copyright (c) 2007-2018 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System.Collections.Generic;

namespace osu.Framework.Allocation
{
    public class ObjectStack<T> where T : new()
    {
        private readonly int maxAmountObjects;
        private readonly Stack<T> freeObjects = new Stack<T>();
        private readonly HashSet<T> usedObjects = new HashSet<T>();

        public ObjectStack(int maxAmountObjects = -1)
        {
            this.maxAmountObjects = maxAmountObjects;
        }

        private T findFreeObject()
        {
            T o = freeObjects.Count > 0 ? freeObjects.Pop() : new T();

            if (maxAmountObjects == -1 || usedObjects.Count < maxAmountObjects)
                usedObjects.Add(o);

            return o;
        }

        private void returnFreeObject(T o)
        {
            if (usedObjects.Remove(o))
                // We are here if the element was successfully found and removed
                freeObjects.Push(o);<commit_msg>Don't track all used objects<commit_after>﻿// Copyright (c) 2007-2018 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System.Collections.Generic;

namespace osu.Framework.Allocation
{
    public class ObjectStack<T> where T : new()
    {
        private readonly int maxAmountObjects;
        private readonly Stack<T> freeObjects = new Stack<T>();
        private int usedObjects;

        public ObjectStack(int maxAmountObjects = -1)
        {
            this.maxAmountObjects = maxAmountObjects;
        }

        private T findFreeObject()
        {
            T o = freeObjects.Count > 0 ? freeObjects.Pop() : new T();

            if (maxAmountObjects == -1 || usedObjects < maxAmountObjects)
                usedObjects++;

            return o;
        }

        private void returnFreeObject(T o)
        {
            if (usedObjects-- > 0)
                // We are here if the element was successfully found and removed
                freeObjects.Push(o);
{'fraction_non_alphanumeric': 0.09669920966992096, 'fraction_numerical': 0.010692701069270108, 'mean_word_length': 2.1098265895953756, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 2, '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': '1773745', 'n_tokens_mistral': 598, 'n_tokens_neox': 563, 'n_words': 165}