Ejemplo n.º 1
0
        public static long IndexOf(this IMemoryList <byte> sequence, byte value)
        {
            var  first = sequence.Memory.Span;
            long index = first.IndexOf(value);

            if (index != -1)
            {
                return(index);
            }

            Position position     = default;
            int      virtualIndex = first.Length;

            while (sequence.TryGet(ref position, out ReadOnlyMemory <byte> memory))
            {
                index = memory.Span.IndexOf(value);
                if (index != -1)
                {
                    return(index + virtualIndex);
                }
                virtualIndex += memory.Length;
            }

            return(-1);
        }
Ejemplo n.º 2
0
        // TODO (pri 3): do we want this to be public? Maybe Lazy<int> length?
        // TODO (pri 3): the problem is that this makes the type mutable, and since the type is a struct, the mutation can be lost when the stack unwinds.
        public int ComputeLength()
        {
            if (_length != Unspecified)
            {
                return(_length);
            }

            int length = 0;

            if (_rest != null)
            {
                Position      position = new Position();
                Memory <byte> segment;
                while (_rest.TryGet(ref position, out segment))
                {
                    length += segment.Length;
                }
            }
            return(length + _first.Length);
        }