Example #1
0
        public int GetPropertiesByInsertionOrder(PropertiesInsertionBuffer buffers)
        {
            if (_metadataPtr == null)
            {
                ThrowObjectDisposed();
            }

            if (buffers.Properties == null ||
                buffers.Properties.Length < _propCount)
            {
                var size = Bits.NextPowerOf2(_propCount);
                buffers.Properties = new int[size];
                buffers.Offsets    = new int[size];
            }

            var metadataSize = _currentOffsetSize + _currentPropertyIdSize + sizeof(byte);

            for (int i = 0; i < _propCount; i++)
            {
                var propertyIntPtr = _metadataPtr + i * metadataSize;
                buffers.Offsets[i]    = ReadNumber(propertyIntPtr, _currentOffsetSize);
                buffers.Properties[i] = i;
            }

            Sorter <int, int, NumericDescendingComparer> sorter;

            sorter.Sort(buffers.Offsets, buffers.Properties, 0, _propCount);
            return(_propCount);
        }
Example #2
0
        protected bool Equals(BlittableJsonReaderObject other)
        {
            if (_propCount != other._propCount)
            {
                return(false);
            }

            if (_propCount == 0)
            {
                return(true);
            }

            if (_isRoot == false && other._isRoot == false)
            {
                var buffer = new PropertiesInsertionBuffer();

                GetPropertiesByInsertionOrder(buffer);

                var dataStart = _objStart - buffer.Offsets[0];
                var dataSize  = _objStart - dataStart;

                other.GetPropertiesByInsertionOrder(buffer);

                var otherDataStart = other._objStart - buffer.Offsets[0];
                var otherDataSize  = other._objStart - otherDataStart;

                if (dataSize == otherDataSize && dataSize < int.MaxValue)
                {
                    if (Memory.CompareInline(dataStart, otherDataStart, (int)dataSize) == 0)
                    {
                        // data of property values is the same, we also need to check names of properties
                        // they as are defined in root so it requires separate check

                        return(HasSamePropertyNames(other));
                    }
                }
            }
            else if (_isRoot && other._isRoot)
            {
                if (_size == other.Size && Memory.CompareInline(_mem, other._mem, _size) == 0)
                {
                    return(true);
                }
            }

            foreach (var propertyName in GetPropertyNames())
            {
                if (other.TryGetMember(propertyName, out object result) == false)
                {
                    return(false);
                }

                var current = this[propertyName];

                if (current == null && result == null)
                {
                    continue;
                }

                if ((current?.Equals(result) ?? false) == false)
                {
                    return(false);
                }
            }

            return(true);
        }