ByteArray.st
branchjv
changeset 19659 0f585374259a
parent 19635 875eb54afd2c
parent 19645 053a5232234d
child 19811 65fec19facb0
equal deleted inserted replaced
19658:cb18e7c8fb6d 19659:0f585374259a
   160     }
   160     }
   161 out:;
   161 out:;
   162 %}.
   162 %}.
   163     ^ self basicNew:anInteger
   163     ^ self basicNew:anInteger
   164 ! !
   164 ! !
   165 
       
   166 
   165 
   167 
   166 
   168 
   167 
   169 !ByteArray class methodsFor:'queries'!
   168 !ByteArray class methodsFor:'queries'!
   170 
   169 
  2868      #[1 2 3 1 2 3 1 2 19] max
  2867      #[1 2 3 1 2 3 1 2 19] max
  2869      #[] max
  2868      #[] max
  2870     "
  2869     "
  2871 !
  2870 !
  2872 
  2871 
       
  2872 startsWith:aByteOrByteArray
       
  2873     "return true, if the receiver starts with something, aStringOrChar.
       
  2874      If the argument is empty, true is returned.
       
  2875      Notice, that this is similar to, but slightly different from VW's and Squeak's beginsWith:,
       
  2876      which are both inconsistent w.r.t. an empty argument."
       
  2877 
       
  2878 %{  /* NOCONTEXT */
       
  2879     int len1, len2;
       
  2880     REGISTER unsigned char *src1, *src2;
       
  2881     unsigned char c;
       
  2882     REGISTER OBJ slf = self;
       
  2883 
       
  2884     if (__qIsByteArrayLike(slf) &&__isByteArrayLike(aByteOrByteArray)) {
       
  2885         src1 = __byteArrayVal(slf);
       
  2886         src2 = __byteArrayVal(aByteOrByteArray);
       
  2887 
       
  2888         if (src1[0] != src2[0]) {
       
  2889             if (__qSize(aByteOrByteArray) == OHDR_SIZE) {
       
  2890                 RETURN (true);
       
  2891             }
       
  2892             RETURN ( false );
       
  2893         }
       
  2894 
       
  2895         len1 = __qSize(slf);
       
  2896         len2 = __qSize(aByteOrByteArray);
       
  2897         if (len1 < len2) {
       
  2898             RETURN ( false );
       
  2899         }
       
  2900 
       
  2901 # ifdef UINT64
       
  2902         while (len2 > (OHDR_SIZE+sizeof(UINT64))) {
       
  2903             if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) {
       
  2904                 RETURN (false);
       
  2905             }
       
  2906             len2 -= sizeof(UINT64);
       
  2907             src1 += sizeof(UINT64);
       
  2908             src2 += sizeof(UINT64);
       
  2909         }
       
  2910 # else
       
  2911 #  ifdef __UNROLL_LOOPS__
       
  2912         while (len2 > (OHDR_SIZE+sizeof(INT)*4)) {
       
  2913             if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
       
  2914                 RETURN (false);
       
  2915             }
       
  2916             if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) {
       
  2917                 RETURN (false);
       
  2918             }
       
  2919             if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) {
       
  2920                 RETURN (false);
       
  2921             }
       
  2922             if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) {
       
  2923                 RETURN (false);
       
  2924             }
       
  2925             len2 -= sizeof(INT)*4;
       
  2926             src1 += sizeof(INT)*4;
       
  2927             src2 += sizeof(INT)*4;
       
  2928         }
       
  2929 #  endif /* __UNROLL_LOOPS__ */
       
  2930 # endif /* UINT64 */
       
  2931 
       
  2932         while (len2 > (OHDR_SIZE+sizeof(INT))) {
       
  2933             if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
       
  2934                 RETURN (false);
       
  2935             }
       
  2936             len2 -= sizeof(INT);
       
  2937             src1 += sizeof(INT);
       
  2938             src2 += sizeof(INT);
       
  2939         }
       
  2940 
       
  2941         for ( ; len2 > (OHDR_SIZE+sizeof(INT)); len2++) {
       
  2942             if (*src1++ != *src2++) {
       
  2943                 RETURN (false);
       
  2944             }
       
  2945         }    
       
  2946         RETURN (true);
       
  2947     }
       
  2948     if (__isSmallInteger(aByteOrByteArray)) {
       
  2949         int val = __intVal(aByteOrByteArray);
       
  2950         if (__byteArraySize(slf) > 0) {
       
  2951             RETURN ( (__byteArrayVal(slf)[0] == val) ? true : false);
       
  2952         }
       
  2953         RETURN ( false );
       
  2954     }
       
  2955 %}.
       
  2956     ^ super startsWith:aByteOrByteArray
       
  2957 
       
  2958     "
       
  2959      #[1 2 3 4 5 6 7 8 9 10] startsWith:#[ 1 2 3 4 5]
       
  2960      #[1 2 3 4 5 6 7 8 9 10] startsWith:#[ 0 1 2 3 4 5]
       
  2961      #[1 2 3 4 5 6 7 8 9 10] startsWith:#(1 2 3 4 5)
       
  2962      #[1 2 3 4 5 6 7 8 9 10] startsWith:1
       
  2963      #[1 2 3 4 5 6 7 8 9 10] startsWith:2
       
  2964     "
       
  2965 !
       
  2966 
  2873 usageCounts
  2967 usageCounts
  2874     "return an array filled with value-counts -
  2968     "return an array filled with value-counts -
  2875      This is needed in the bitmap/image classes to get info on color usage.
  2969      This is needed in the bitmap/image classes to get info on color usage.
  2876      (i.e. to build up a histogram of color usage within an image)."
  2970      (i.e. to build up a histogram of color usage within an image)."
  2877 
  2971 
  3061     "
  3155     "
  3062      #[1 2 3 4 5 6 7 8 9 0 1 2 3 4 5] indexOf:0 startingAt:1
  3156      #[1 2 3 4 5 6 7 8 9 0 1 2 3 4 5] indexOf:0 startingAt:1
  3063     "
  3157     "
  3064 ! !
  3158 ! !
  3065 
  3159 
       
  3160 
  3066 !ByteArray methodsFor:'testing'!
  3161 !ByteArray methodsFor:'testing'!
  3067 
  3162 
  3068 isByteArray
  3163 isByteArray
  3069     "return true, if the receiver is some kind of bytearray;
  3164     "return true, if the receiver is some kind of bytearray;
  3070      true is returned here - the method is redefined from Object."
  3165      true is returned here - the method is redefined from Object."
  3085     ^ self class == ByteArray
  3180     ^ self class == ByteArray
  3086 
  3181 
  3087     "Modified: 22.4.1996 / 12:55:30 / cg"
  3182     "Modified: 22.4.1996 / 12:55:30 / cg"
  3088 ! !
  3183 ! !
  3089 
  3184 
  3090 
       
  3091 !ByteArray class methodsFor:'documentation'!
  3185 !ByteArray class methodsFor:'documentation'!
  3092 
  3186 
  3093 version
  3187 version
  3094     ^ '$Header$'
  3188     ^ '$Header$'
  3095 !
  3189 !