Example #1
0
        internal int CompareDataInline(Slice other, ushort size)
        {
            if (Array != null)
            {
                fixed(byte *a = Array)
                {
                    if (other.Array != null)
                    {
                        fixed(byte *b = other.Array)
                        {
                            return(MemoryUtils.CompareInline(a, b, size));
                        }
                    }
                    else
                    {
                        return(MemoryUtils.CompareInline(a, other.Pointer, size));
                    }
                }
            }

            if (other.Array != null)
            {
                fixed(byte *b = other.Array)
                {
                    return(MemoryUtils.CompareInline(Pointer, b, size));
                }
            }
            else
            {
                return(MemoryUtils.CompareInline(Pointer, other.Pointer, size));
            }
        }
Example #2
0
        public static int CompareInline(Slice x, Slice y)
        {
            Debug.Assert(x.Options == SliceOptions.Key);
            Debug.Assert(y.Options == SliceOptions.Key);

            var srcKey   = x.KeyLength;
            var otherKey = y.KeyLength;
            var size     = srcKey <= otherKey ? srcKey : otherKey;

            int r = 0;

            unsafe
            {
                if (x.Array != null)
                {
                    fixed(byte *a = x.Array)
                    {
                        if (y.Array != null)
                        {
                            fixed(byte *b = y.Array)
                            {
                                r = MemoryUtils.CompareInline(a, b, size);
                            }
                        }
                        else
                        {
                            r = MemoryUtils.CompareInline(a, y.Pointer, size);
                        }
                    }
                }
                else
                {
                    if (y.Array != null)
                    {
                        fixed(byte *b = y.Array)
                        {
                            r = MemoryUtils.CompareInline(x.Pointer, b, size);
                        }
                    }
                    else
                    {
                        r = MemoryUtils.CompareInline(x.Pointer, y.Pointer, size);
                    }
                }
            }

            if (r != 0)
            {
                return(r);
            }

            return(srcKey - otherKey);
        }