String.st
branchjv
changeset 18308 0e48540e3b9f
parent 18292 8d4fe353a2d2
parent 18306 efb1f01b24e2
child 18345 fb699032075a
equal deleted inserted replaced
18304:424139e100b2 18308:0e48540e3b9f
   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 
   998 				    RETURN ( __mkSmallInteger(index) );
  1008 				    RETURN ( __mkSmallInteger(index) );
   999 				}
  1009 				}
  1000 				index++;
  1010 				index++;
  1001 			    }
  1011 			    }
  1002 			}
  1012 			}
       
  1013 #  endif
  1003 # endif
  1014 # endif
  1004 #endif
       
  1005 		    }
  1015 		    }
  1006 		}
  1016 		}
  1007 	    }
  1017 	    }
  1008 	    RETURN ( __mkSmallInteger(0) );
  1018 	    RETURN ( __mkSmallInteger(0) );
  1009 	}
  1019 	}
  1010     }
  1020     }
  1011 #undef V2
  1021 # undef V2
       
  1022 #endif /* not SCHTEAM */
  1012 %}.
  1023 %}.
  1013     ^ super indexOf:aCharacter startingAt:start
  1024     ^ super indexOf:aCharacter startingAt:start
  1014 
  1025 
  1015     "
  1026     "
  1016      'hello world' indexOf:$0 startingAt:1
  1027      'hello world' indexOf:$0 startingAt:1
  4308 ! !
  4319 ! !
  4309 
  4320 
  4310 !String class methodsFor:'documentation'!
  4321 !String class methodsFor:'documentation'!
  4311 
  4322 
  4312 version
  4323 version
  4313     ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.336 2015-04-26 11:18:39 cg Exp $'
  4324     ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.337 2015-04-29 11:22:57 cg Exp $'
  4314 !
  4325 !
  4315 
  4326 
  4316 version_CVS
  4327 version_CVS
  4317     ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.336 2015-04-26 11:18:39 cg Exp $'
  4328     ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.337 2015-04-29 11:22:57 cg Exp $'
  4318 ! !
  4329 ! !