<commit_before>﻿using System;

namespace Dragonfly.Http
{
    public class Baton
    {
        public ArraySegment<byte> Buffer { get; set; }
        public bool Complete { get; set; }
        public Connection.Next Next { get; set; }


        public void Skip(int count)
        {
            Buffer = new ArraySegment<byte>(Buffer.Array, Buffer.Offset + count, Buffer.Count - count);
        }

        public ArraySegment<byte> Take(int count)
        {
            var taken = new ArraySegment<byte>(Buffer.Array, Buffer.Offset, count);
            Skip(count);
            return taken;
        }

        public ArraySegment<byte> Available(int minimumSize)
        {
            if (Buffer.Count == 0 && Buffer.Offset != 0)
                Buffer = new ArraySegment<byte>(Buffer.Array, 0, 0);

            var availableSize = Buffer.Array.Length - Buffer.Offset - Buffer.Count;

            if (availableSize < minimumSize)
            {
                if (availableSize + Buffer.Offset >= minimumSize && false)
                {
                    Array.Copy(Buffer.Array, Buffer.Offset, Buffer.Array, 0, Buffer.Count);
                    Buffer = new ArraySegment<byte>(Buffer.Array, 0, Buffer.Count);
                    availableSize = Buffer.Array.Length - Buffer.Offset - Buffer.Count;
                }
                else
                {
                    var larger = new ArraySegment<byte>(new byte[Buffer.Array.Length * 2 + minimumSize], 0, Buffer.Count);
                    Array.Copy(Buffer.Array, Buffer.Offset, larger.Array, 0, Buffer.Count);
                    Buffer = larger;
                    availableSize = Buffer.Array.Length - Buffer.Offset - Buffer.Count;
                }
            }
            return new ArraySegment<byte>(Buffer.Array, Buffer.Offset + Buffer.Count, availableSize);
        }

        public void Extend(int count)
        {
            Buffer = new ArraySegment<byte>(Buffer.Array, Buffer.Offset, Buffer.Count + count);
        }

    }
}<commit_msg>Adding debug asserts around some questionable values<commit_after>﻿using System;
using System.Diagnostics;

namespace Dragonfly.Http
{
    public class Baton
    {
        public ArraySegment<byte> Buffer { get; set; }
        public bool Complete { get; set; }
        public Connection.Next Next { get; set; }


        public void Skip(int count)
        {
            Buffer = new ArraySegment<byte>(Buffer.Array, Buffer.Offset + count, Buffer.Count - count);
        }

        public ArraySegment<byte> Take(int count)
        {
            var taken = new ArraySegment<byte>(Buffer.Array, Buffer.Offset, count);
            Skip(count);
            return taken;
        }

        public ArraySegment<byte> Available(int minimumSize)
        {
            if (Buffer.Count == 0 && Buffer.Offset != 0)
                Buffer = new ArraySegment<byte>(Buffer.Array, 0, 0);

            var availableSize = Buffer.Array.Length - Buffer.Offset - Buffer.Count;

            if (availableSize < minimumSize)
            {
                if (availableSize + Buffer.Offset >= minimumSize)
                {
                    Array.Copy(Buffer.Array, Buffer.Offset, Buffer.Array, 0, Buffer.Count);
                    Buffer = new ArraySegment<byte>(Buffer.Array, 0, Buffer.Count);
                    availableSize = Buffer.Array.Length - Buffer.Offset - Buffer.Count;
                }
                else
                {
                    var larger = new ArraySegment<byte>(new byte[Buffer.Array.Length * 2 + minimumSize], 0, Buffer.Count);
                    Array.Copy(Buffer.Array, Buffer.Offset, larger.Array, 0, Buffer.Count);
                    Buffer = larger;
                    availableSize = Buffer.Array.Length - Buffer.Offset - Buffer.Count;
                }
            }
            return new ArraySegment<byte>(Buffer.Array, Buffer.Offset + Buffer.Count, availableSize);
        }

        public void Extend(int count)
        {
            Debug.Assert(count >= 0);
            Debug.Assert(Buffer.Offset >= 0);
            Debug.Assert(Buffer.Offset <= Buffer.Array.Length);
            Debug.Assert(Buffer.Offset + Buffer.Count <= Buffer.Array.Length);
            Debug.Assert(Buffer.Offset + Buffer.Count + count <= Buffer.Array.Length);

            Buffer = new ArraySegment<byte>(Buffer.Array, Buffer.Offset, Buffer.Count + count);
        }

    }
}
{'fraction_non_alphanumeric': 0.1036516216829213, 'fraction_numerical': 0.004536176003628941, 'mean_word_length': 1.7374301675977655, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 27, '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': '5915725', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1078, 'n_words': 268}