920 "return the index of the first occurrence of the argument, aCharacter |
920 "return the index of the first occurrence of the argument, aCharacter |
921 in myself starting at start, anInteger or 0 if not found; |
921 in myself starting at start, anInteger or 0 if not found; |
922 - reimplemented here for speed" |
922 - reimplemented here for speed" |
923 |
923 |
924 %{ /* NOCONTEXT */ |
924 %{ /* NOCONTEXT */ |
925 #undef __UNROLL_LOOPS__ |
925 #ifdef __SCHTEAM__ |
926 #undef FAST_MEMCHR |
926 if (start.isSmallInteger() |
927 #define V2 |
927 && aCharacter.isSTCharacter()) { |
|
928 int idx1Based = start.intValue(); // st index is 1 based |
|
929 int jIdx = self.asString().indexOf(aCharacter.charValue(), idx1Based-1); |
|
930 |
|
931 return context._RETURN( jIdx+1 ); // st index is 1 based |
|
932 } |
|
933 |
|
934 #else |
|
935 # undef __UNROLL_LOOPS__ |
|
936 # undef FAST_MEMCHR |
|
937 # define V2 |
928 |
938 |
929 REGISTER unsigned char *cp; |
939 REGISTER unsigned char *cp; |
930 #ifdef FAST_MEMCHR |
940 # ifdef FAST_MEMCHR |
931 REGISTER unsigned char *ncp; |
941 REGISTER unsigned char *ncp; |
932 #endif |
942 # endif |
933 REGISTER INT index; |
943 REGISTER INT index; |
934 REGISTER unsigned byteValue; |
944 REGISTER unsigned byteValue; |
935 int last; |
945 int last; |
936 OBJ cls; |
946 OBJ cls; |
937 |
947 |
948 |
958 |
949 cp += numInstBytes; |
959 cp += numInstBytes; |
950 last -= numInstBytes; |
960 last -= numInstBytes; |
951 } |
961 } |
952 if (index <= last) { |
962 if (index <= last) { |
953 #ifdef FAST_MEMCHR |
963 # ifdef FAST_MEMCHR |
954 ncp = (unsigned char *) memchr(cp+index-1, byteValue, last+1-index); |
964 ncp = (unsigned char *) memchr(cp+index-1, byteValue, last+1-index); |
955 if (ncp) { |
965 if (ncp) { |
956 RETURN ( __mkSmallInteger(ncp - cp + 1) ); |
966 RETURN ( __mkSmallInteger(ncp - cp + 1) ); |
957 } |
967 } |
958 #else |
968 # else |
959 # ifdef __UNROLL_LOOPS__ |
969 # ifdef __UNROLL_LOOPS__ |
960 { |
970 { |
961 int last3 = last-3; |
971 int last3 = last-3; |
962 |
972 |
963 for (; index <= last3; index += 4) { |
973 for (; index <= last3; index += 4) { |
964 if (cp[index-1] == byteValue) { RETURN ( __mkSmallInteger(index) ); } |
974 if (cp[index-1] == byteValue) { RETURN ( __mkSmallInteger(index) ); } |
965 if (cp[index-1+1] == byteValue) { RETURN ( __mkSmallInteger(index+1) ); } |
975 if (cp[index-1+1] == byteValue) { RETURN ( __mkSmallInteger(index+1) ); } |
966 if (cp[index-1+2] == byteValue) { RETURN ( __mkSmallInteger(index+2) ); } |
976 if (cp[index-1+2] == byteValue) { RETURN ( __mkSmallInteger(index+2) ); } |
967 if (cp[index-1+3] == byteValue) { RETURN ( __mkSmallInteger(index+3) ); } |
977 if (cp[index-1+3] == byteValue) { RETURN ( __mkSmallInteger(index+3) ); } |
968 } |
978 } |
969 } |
979 } |
970 # endif |
980 # endif |
971 # ifdef V1 |
981 # ifdef V1 |
972 for (; index <= last; index++) { |
982 for (; index <= last; index++) { |
973 if (cp[index-1] == byteValue) { |
983 if (cp[index-1] == byteValue) { |
974 RETURN ( __mkSmallInteger(index) ); |
984 RETURN ( __mkSmallInteger(index) ); |
975 } |
985 } |
976 } |
986 } |
977 # endif |
987 # endif |
978 # ifdef V2 |
988 # ifdef V2 |
979 { |
989 { |
980 // see bit twiddling hacks |
990 // see bit twiddling hacks |
981 # define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL) |
991 # define hasZeroByte(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL) |
982 # define hasByteM(v,m) hasZeroByte( (v) ^ m) |
992 # define hasByteM(v,m) hasZeroByte( (v) ^ m) |
983 |
993 |