<commit_before>package org.boon.primitive;

public class ByteBuf {

    protected int capacity = 16;


    protected int length = 0;

    protected byte [] buffer;


    public static ByteBuf createExact( final int capacity) {
        return new ByteBuf(capacity) {
            public void add(byte[] chars) {
                Byt._idx( buffer, length, chars );
                length += chars.length;
            }
        };
    }

    public static ByteBuf create( int capacity) {
        return new ByteBuf(capacity);
    }

    public static ByteBuf create( byte [] buffer) {
        ByteBuf buf = new ByteBuf(buffer.length);
        buf.buffer = buffer;
        return buf;
    }

    protected ByteBuf(int capacity)  {
        this.capacity = capacity;
        init();
    }


    protected ByteBuf()  {
        init();
    }

    private void init() {
        buffer = new byte[capacity];
    }


    public void add(String str) {
            this.add( Byt.bytes(str) );

    }


    public void add(int value) {

        if (4 + length < capacity) {
            Byt.intTo(buffer, length, value);
        } else {
            buffer = Byt.grow(buffer, buffer.length * 2 + 4 );
            capacity = buffer.length;

            Byt.intTo(buffer, length, value);
        }

        length += 4;


    }


    public void add(float value) {

        if (4 + length < capacity) {
            Byt.floatTo(buffer, length, value);
        } else {
            buffer = Byt.grow(buffer,  buffer.length * 2 + 4 );
            capacity = buffer.length;

            Byt.floatTo(buffer, length, value);
        }

        length += 4;


    }



    public void add(char value) {

        if (2 + length < capacity) {
            Byt.charTo(buffer, length, value);
        } else {
            buffer = Byt.grow(buffer,  buffer.length * 2 + 2 );
            capacity = buffer.length;

            Byt.charTo(buffer, length, value);
        }

        length += 2;


    }



    public void add(short value) {

        if (2 + length < capacity) {
            Byt.shortTo(buffer, length, value);
        } else {
            buffer = Byt.grow(buffer,  buffer.length * 2 + 2 );
            capacity = buffer.length;

            Byt.shortTo(buffer, length, value);
        }

        length += 2;


    }

    public void add(byte value) {

        if (1 + length < capacity) {
            Byt.idx(buffer, length, value);
        } else {
            buffer = Byt.grow(buffer);
            capacity = buffer.length;

            Byt.idx(buffer, length, value);
        }

        length += 1;


    }

    public void add(long value) {

        if (8 + length < capacity) {
            Byt.longTo(buffer, length, value);
        } else {
            buffer = Byt.grow(buffer,  buffer.length * 2 + 8 );
            capacity = buffer.length;

            Byt.longTo(buffer, length, value);
        }

        length += 8;

    }

    public void add(double value) {

        if (8 + length < capacity) {
            Byt.doubleTo(buffer, length, value);
        } else {
            buffer = Byt.grow(buffer,  buffer.length * 2 + 8 );
            capacity = buffer.length;

            Byt.doubleTo(buffer, length, value);
        }

        length += 8;

    }


    public void add(byte[] array) {
        if (array.length + length < capacity) {
            Byt._idx( buffer, length, array );
        } else {
            buffer = Byt.grow(buffer,  buffer.length * 2 + array.length );
            capacity = buffer.length;

            Byt._idx(buffer, length, array);

        }
        length += array.length;
    }

    public byte[] readAndReset () {
        byte [] bytes = this.buffer;
        this.buffer = null;
        return bytes;
    }


    public int len() {
        return length;<commit_msg>recycle buf for highspeed I/O<commit_after>package org.boon.primitive;

public class ByteBuf {

    protected int capacity = 16;


    protected int length = 0;

    protected byte [] buffer;


    public static ByteBuf createExact( final int capacity) {
        return new ByteBuf(capacity) {
            public void add(byte[] chars) {
                Byt._idx( buffer, length, chars );
                length += chars.length;
            }
        };
    }

    public static ByteBuf create( int capacity) {
        return new ByteBuf(capacity);
    }

    public static ByteBuf create( byte [] buffer) {
        ByteBuf buf = new ByteBuf(buffer.length);
        buf.buffer = buffer;
        return buf;
    }

    protected ByteBuf(int capacity)  {
        this.capacity = capacity;
        init();
    }


    protected ByteBuf()  {
        init();
    }

    private void init() {
        buffer = new byte[capacity];
    }


    public void add(String str) {
            this.add( Byt.bytes(str) );

    }


    public void add(int value) {

        if (4 + length < capacity) {
            Byt.intTo(buffer, length, value);
        } else {
            buffer = Byt.grow(buffer, buffer.length * 2 + 4 );
            capacity = buffer.length;

            Byt.intTo(buffer, length, value);
        }

        length += 4;


    }


    public void add(float value) {

        if (4 + length < capacity) {
            Byt.floatTo(buffer, length, value);
        } else {
            buffer = Byt.grow(buffer,  buffer.length * 2 + 4 );
            capacity = buffer.length;

            Byt.floatTo(buffer, length, value);
        }

        length += 4;


    }



    public void add(char value) {

        if (2 + length < capacity) {
            Byt.charTo(buffer, length, value);
        } else {
            buffer = Byt.grow(buffer,  buffer.length * 2 + 2 );
            capacity = buffer.length;

            Byt.charTo(buffer, length, value);
        }

        length += 2;


    }



    public void add(short value) {

        if (2 + length < capacity) {
            Byt.shortTo(buffer, length, value);
        } else {
            buffer = Byt.grow(buffer,  buffer.length * 2 + 2 );
            capacity = buffer.length;

            Byt.shortTo(buffer, length, value);
        }

        length += 2;


    }

    public void add(byte value) {

        if (1 + length < capacity) {
            Byt.idx(buffer, length, value);
        } else {
            buffer = Byt.grow(buffer);
            capacity = buffer.length;

            Byt.idx(buffer, length, value);
        }

        length += 1;


    }

    public void add(long value) {

        if (8 + length < capacity) {
            Byt.longTo(buffer, length, value);
        } else {
            buffer = Byt.grow(buffer,  buffer.length * 2 + 8 );
            capacity = buffer.length;

            Byt.longTo(buffer, length, value);
        }

        length += 8;

    }

    public void add(double value) {

        if (8 + length < capacity) {
            Byt.doubleTo(buffer, length, value);
        } else {
            buffer = Byt.grow(buffer,  buffer.length * 2 + 8 );
            capacity = buffer.length;

            Byt.doubleTo(buffer, length, value);
        }

        length += 8;

    }


    public void add(byte[] array) {
        if (array.length + length < capacity) {
            Byt._idx( buffer, length, array );
        } else {
            buffer = Byt.grow(buffer,  buffer.length * 2 + array.length );
            capacity = buffer.length;

            Byt._idx(buffer, length, array);

        }
        length += array.length;
    }

    public byte[] readAndReset () {
        byte [] bytes = this.buffer;
        this.buffer = null;
        return bytes;
    }

    public byte[] readForRecycle () {
        this.length = 0;
        return  this.buffer;
    }

    public int len() {
        return length;
{'fraction_non_alphanumeric': 0.11272350349831563, 'fraction_numerical': 0.00790360196942213, 'mean_word_length': 1.4948287007110537, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 3, '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': '5098909', 'n_tokens_mistral': 2352, 'n_tokens_neox': 2157, 'n_words': 580}