private static T[] BuilderInsert <T>(T[] array, int index, T item, ArrayPooler <T> arrayPool)
        {
            var newArray = arrayPool.Get(array.Length + 1);

            newArray[index] = item;

            if (array.Length == 0)
            {
                arrayPool.Return(array);
                return(newArray);
            }

            int s = 0;

            for (int d = 0; d != index; ++s, ++d)
            {
                newArray[d] = array[s];
            }

            for (int d = index + 1; d < newArray.Length; ++s, ++d)
            {
                newArray[d] = array[s];
            }

            arrayPool.Return(array);
            return(newArray);
        }
        private static T[] BuilderRemoveAt <T>(T[] array, int index, ArrayPooler <T> arrayPool)
        {
            if (array.Length == 1)
            {
                arrayPool.Return(array);
                return(Array.Empty <T>());
            }

            var newArray = arrayPool.Get(array.Length - 1);
            int s        = 0;

            for (int d = 0; d < newArray.Length; ++s, ++d)
            {
                if (s == index)
                {
                    d--;
                    continue;
                }
                newArray[d] = array[s];
            }

            arrayPool.Return(array);
            return(newArray);
        }
Ejemplo n.º 3
0
 public State()
 {
     OwnerToken = new BuilderToken();
     Values     = new ArrayPooler <ValueNode>();
     Branches   = new ArrayPooler <Branch>();
 }