<commit_before>#ifndef OBJECT_BUFFER_HPP
#define OBJECT_BUFFER_HPP

#include "errors.hpp"

template <class T>
class object_buffer_t {
public:

    // TODO: this object makes no guarantees that its parent still exists when it is destroyed
    //  is that ok?
    class destruction_sentinel_t {
    public:
        explicit destruction_sentinel_t(object_buffer_t<T> *_parent) : parent(_parent) { }

        ~destruction_sentinel_t() {
            if (parent->has()) {
                parent->reset();
            }
        }
    private:
        object_buffer_t<T> *parent;
    };

    object_buffer_t() : instantiated(false) { };
    ~object_buffer_t() {
        if (instantiated) {
            reset();
        }
    };

#define OBJECT_BUFFER_CREATE_INTERNAL(...) { rassert(!instantiated); instantiated = true; return new (&object_data[0]) T(__VA_ARGS__); }

    // 9 arguments ought to be enough for anybody
    T * create()
    { OBJECT_BUFFER_CREATE_INTERNAL(); }

    template <class arg1_t>
    T * create(arg1_t arg1)
    { OBJECT_BUFFER_CREATE_INTERNAL(arg1); }

    template <class arg1_t, class arg2_t>
    T * create(const arg1_t &arg1, const arg2_t &arg2)
    { OBJECT_BUFFER_CREATE_INTERNAL(arg1, arg2); }<commit_msg>replaced ad-hoc dynamic memory reduction in wait_any_t with object_buffer_t<commit_after>#ifndef OBJECT_BUFFER_HPP
#define OBJECT_BUFFER_HPP

#include "errors.hpp"

template <class T>
class object_buffer_t {
public:

    // TODO: this object makes no guarantees that its parent still exists when it is destroyed
    //  is that ok?
    class destruction_sentinel_t {
    public:
        explicit destruction_sentinel_t(object_buffer_t<T> *_parent) : parent(_parent) { }

        ~destruction_sentinel_t() {
            if (parent->has()) {
                parent->reset();
            }
        }
    private:
        object_buffer_t<T> *parent;
    };

    object_buffer_t() : instantiated(false) { };
    ~object_buffer_t() {
        if (instantiated) {
            reset();
        }
    };

#define OBJECT_BUFFER_CREATE_INTERNAL(...) { rassert(!instantiated); instantiated = true; return new (&object_data[0]) T(__VA_ARGS__); }

    // 9 arguments ought to be enough for anybody
    T * create()
    { OBJECT_BUFFER_CREATE_INTERNAL(); }

    template <class arg1_t>
    T * create(const arg1_t &arg1)
    { OBJECT_BUFFER_CREATE_INTERNAL(arg1); }

    template <class arg1_t, class arg2_t>
    T * create(const arg1_t &arg1, const arg2_t &arg2)
    { OBJECT_BUFFER_CREATE_INTERNAL(arg1, arg2); }
{'fraction_non_alphanumeric': 0.10684606252473289, 'fraction_numerical': 0.0110803324099723, 'mean_word_length': 2.931570762052877, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '105024', 'n_tokens_mistral': 846, 'n_tokens_neox': 809, 'n_words': 191}