internal override byte[] GetSendBuffer()
 {
     byte[] baseSendBuffer = base.GetSendBuffer();
     ArrayBuilder b = new ArrayBuilder(baseSendBuffer.Length + _sendData.Length);
     b.Append(baseSendBuffer);
     b.Append(_sendData);
     return b.GetBytes();
 }
        internal override byte[] GetSendBuffer()
        {
            byte[]       baseSendBuffer = base.GetSendBuffer();
            ArrayBuilder b = new ArrayBuilder(baseSendBuffer.Length + _sendData.Length);

            b.Append(baseSendBuffer);
            b.Append(_sendData);
            return(b.GetBytes());
        }
Example #3
0
        internal virtual byte[] GetSendBuffer()
        {
            ArrayBuilder b = new ArrayBuilder(4);

            b.Append(_cla);
            b.Append(_ins);
            b.Append(_p1);
            b.Append(_p2);
            return(b.GetBytes());
        }
        public int AddEHInfo(byte[] ehInfo)
        {
            int offset = _ehInfoBuilder.Count;

            _ehInfoBuilder.Append(ehInfo);
            return(offset);
        }
Example #5
0
        protected byte[] GetRuntimeOptionsBlob()
        {
            const int HeaderSize = 4;

            ArrayBuilder <byte> options = new ArrayBuilder <byte>();

            // Reserve space for the header
            options.ZeroExtend(HeaderSize);

            foreach (string option in _runtimeOptions)
            {
                byte[] optionBytes = System.Text.Encoding.ASCII.GetBytes(option);
                options.Append(optionBytes);

                // Emit a null to separate the next option
                options.Add(0);
            }

            byte[] result = options.ToArray();

            int length = options.Count - HeaderSize;

            // Encode the size of the blob into the header
            result[0] = (byte)length;
            result[1] = (byte)(length >> 8);
            result[2] = (byte)(length >> 0x10);
            result[3] = (byte)(length >> 0x18);

            return(result);
        }
Example #6
0
        private static ArrayBuilderSegment <T> ToArrayBuilderSegment <T>(T[] entries)
        {
            var builder = new ArrayBuilder <T>();

            builder.Append(entries, 0, entries.Length);
            return(builder.ToSegment(0, entries.Length));
        }
Example #7
0
        public int AddEHInfo(ObjectData ehInfo)
        {
            int offset = _ehInfoBuilder.Count;

            _ehInfoBuilder.Append(ehInfo.Data);
            _relocs = ehInfo.Relocs;
            return(offset);
        }
Example #8
0
        public static Byte[] ReadAllBytes(this Stream stream, Int32 bufferSize = DefaultBufferSize)
        {
            var result = new ArrayBuilder <Byte>();

            var   buffer = new Byte[bufferSize];
            Int32 len;

            while (0 < (len = stream.Read(buffer, 0, bufferSize)))
            {
                result.Append(buffer, 0, len);
            }

            return(result.ToArray());
        }
        public void StillWorksAfterUnderlyingCapacityChange()
        {
            // Arrange: builder containing 1..8
            using var builder = new ArrayBuilder <int>(minCapacity: 10, new TestArrayPool <int>());
            builder.Append(new[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 0, 8);
            var originalBuffer = builder.Buffer;

            // Act/Assert 1: take segment containing 1..5
            var segment = builder.ToSegment(0, 5);

            Assert.Equal(new[] { 1, 2, 3, 4, 5 }, segment);
            Assert.Same(originalBuffer, segment.Array);

            // Act 2: grow the builder enough to force a resize
            builder.Append(new[] { 9, 10, 11 }, 0, 3);
            Array.Clear(originalBuffer, 0, originalBuffer.Length); // Extra proof that we're not using the original storage

            // Assert 2
            Assert.Same(builder.Buffer, segment.Array);
            Assert.NotSame(originalBuffer, segment.Array); // Since there was a resize
            Assert.Equal(new[] { 1, 2, 3, 4, 5 }, segment);
            Assert.Equal(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }, builder.ToSegment(0, builder.Count));
        }
Example #10
0
    public void Append_FillBuffer()
    {
        // Arrange
        var capacity = 8;

        using var builder = new ArrayBuilder <int>(minCapacity: capacity);

        // Act
        for (var i = 0; i < capacity; i++)
        {
            builder.Append(5);
        }

        // Assert
        Assert.Equal(capacity, builder.Count);
        Assert.Equal(Enumerable.Repeat(5, capacity), builder.Buffer.Take(capacity));
    }
        public void BasicPropertiesWork()
        {
            // Arrange: builder containing 1..5
            using var builder = new ArrayBuilder <int>();
            builder.Append(new[] { 1, 2, 3, 4, 5 }, 0, 5);

            // Act: take segment containing 2..3
            var segment = builder.ToSegment(1, 3);

            // Act
            Assert.Same(builder.Buffer, segment.Array);
            Assert.Equal(1, segment.Offset);
            Assert.Equal(2, segment.Count);
            Assert.Equal(2, segment[0]);
            Assert.Equal(3, segment[1]);
            Assert.Equal(new[] { 2, 3 }, segment);
        }
        /// <summary>
        /// Metadata based computation of interfaces.
        /// </summary>
        private DefType[] ComputeRuntimeInterfacesForNonInstantiatedMetadataType(MetadataType type)
        {
            DefType[] explicitInterfaces = type.ExplicitlyImplementedInterfaces;
            DefType[] baseTypeInterfaces = (type.BaseType != null) ? (type.BaseType.RuntimeInterfaces) : Array.Empty<DefType>();

            // Optimized case for no interfaces newly defined.
            if (explicitInterfaces.Length == 0)
                return baseTypeInterfaces;

            ArrayBuilder<DefType> interfacesArray = new ArrayBuilder<DefType>();
            interfacesArray.Append(baseTypeInterfaces);

            foreach (DefType iface in explicitInterfaces)
            {
                BuildPostOrderInterfaceList(iface, ref interfacesArray);
            }

            return interfacesArray.ToArray();
        }
Example #13
0
    internal void AddDiff(RenderTreeDiff diff)
    {
        var componentId = diff.ComponentId;

        if (!DiffsByComponentId.ContainsKey(componentId))
        {
            DiffsByComponentId.Add(componentId, new List <RenderTreeDiff>());
        }

        // Clone the diff, because its underlying storage will get reused in subsequent batches
        var cloneBuilder = new ArrayBuilder <RenderTreeEdit>();

        cloneBuilder.Append(diff.Edits.ToArray(), 0, diff.Edits.Count);
        var diffClone = new RenderTreeDiff(
            diff.ComponentId,
            cloneBuilder.ToSegment(0, diff.Edits.Count));

        DiffsByComponentId[componentId].Add(diffClone);
        DiffsInOrder.Add(diffClone);
    }
        /// <summary>
        /// Metadata based computation of interfaces.
        /// </summary>
        private DefType[] ComputeRuntimeInterfacesForNonInstantiatedMetadataType(MetadataType type)
        {
            DefType[] explicitInterfaces = type.ExplicitlyImplementedInterfaces;
            DefType[] baseTypeInterfaces = (type.BaseType != null) ? (type.BaseType.RuntimeInterfaces) : Array.Empty <DefType>();

            // Optimized case for no interfaces newly defined.
            if (explicitInterfaces.Length == 0)
            {
                return(baseTypeInterfaces);
            }

            ArrayBuilder <DefType> interfacesArray = new ArrayBuilder <DefType>();

            interfacesArray.Append(baseTypeInterfaces);

            foreach (DefType iface in explicitInterfaces)
            {
                BuildPostOrderInterfaceList(iface, ref interfacesArray);
            }

            return(interfacesArray.ToArray());
        }
Example #15
0
 public void AddDisposedComponentId(int componentId)
 => _disposedComponentIds.Append(componentId);
Example #16
0
 public void WriteString(Utf8String utf8String)
 {
     _data.Append(utf8String.UnderlyingArray);
     _data.Add(0);
 }
Example #17
0
 internal virtual byte[] GetSendBuffer()
 {
     ArrayBuilder b = new ArrayBuilder(4);
     b.Append(_cla);
     b.Append(_ins);
     b.Append(_p1);
     b.Append(_p2);
     return b.GetBytes();
 }
Example #18
0
 public static ArrayBuilder <T> AddTo <T>(ArrayBuilder <T> builder, T element) => builder.Append(element);
Example #19
0
 /// <inheritdoc/>
 public override ArrayBuilder Reconstruct(ArrayBuilder ab)
 {
     return(ab.Append(Other(ab.Prev())));
 }
 public void EmitBlob(byte[] blob)
 {
     _currentObjectData.Append(blob);
 }
Example #21
0
 public void AddDisposedEventHandlerId(int attributeEventHandlerId)
 => _disposedEventHandlerIds.Append(attributeEventHandlerId);
Example #22
0
 public void EmitBytes(byte[] bytes)
 {
     _data.Append(bytes);
 }