Example #1
0
        internal unsafe static int UnsafeIndexOf(char *chars, int length, int start, BooleanDecisionTree toMatch, Func <Vector <ushort>, Vector <ushort> > toMatchCompiled)
        {
            //System.Diagnostics.Debug.Assert(Vector.IsHardwareAccelerated);
            int i       = start;
            int lastVec = length - vecUshortSize;

            for (; i <= lastVec; i += vecUshortSize)
            {
                var vec      = Unsafe.Read <Vector <ushort> >(chars + i);
                var matching = toMatchCompiled(vec);
                if (!Vector.EqualsAll(matching, Vector <ushort> .Zero))
                {
                    for (int j = 0; j < vecUshortSize; ++j)
                    {
                        if (matching[j] != 0)
                        {
                            return(i + j);
                        }
                    }
                }
            }
            for (; i < length; ++i)
            {
                if (toMatch.Contains(chars[i]))
                {
                    return(i);
                }
            }
            return(-1);
        }
Example #2
0
        internal unsafe static int UnsafeIndexOf(char *chars, int length, int start, BooleanDecisionTree toMatch, Vector <ushort>[] toMatchVecs)
        {
            //System.Diagnostics.Debug.Assert(Vector.IsHardwareAccelerated);
            fixed(bool *toMatch_precomputed = toMatch.precomputed)
            {
                int i       = start;
                int lastVec = length - vecUshortSize;
                int toMatch_precomputed_length = toMatch.precomputed.Length;
                int toMatchVecs_Length         = toMatchVecs.Length;

                for (; i <= lastVec; i += vecUshortSize)
                {
                    var vec = Unsafe.Read <Vector <ushort> >(chars + i);
                    for (int k = 0; k < toMatchVecs_Length; k++)
                    {
                        var searchVec = toMatchVecs[k];
                        if (Vector.EqualsAny(vec, searchVec))
                        {
                            for (int j = 0; j < vecUshortSize; ++j)
                            {
                                int ij = i + j;
                                var c  = chars[ij];
                                if (c < toMatch_precomputed_length ? toMatch_precomputed[c] : toMatch.bst.Find(c) == 1)
                                {
                                    return(ij);
                                }
                            }
                        }
                    }
                }
                for (; i < length; ++i)
                {
                    if (toMatch.Contains(chars[i]))
                    {
                        return(i);
                    }
                }
                return(-1);
            }
        }