Merge jv
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 25 Apr 2016 10:19:26 +0100
branchjv
changeset 19659 0f585374259a
parent 19658 cb18e7c8fb6d (current diff)
parent 19645 053a5232234d (diff)
child 19660 d48041817c55
Merge
ByteArray.st
HashStream.st
--- a/ByteArray.st	Sat Apr 23 09:05:39 2016 +0100
+++ b/ByteArray.st	Mon Apr 25 10:19:26 2016 +0100
@@ -165,7 +165,6 @@
 
 
 
-
 !ByteArray class methodsFor:'queries'!
 
 elementByteSize
@@ -2870,6 +2869,101 @@
     "
 !
 
+startsWith:aByteOrByteArray
+    "return true, if the receiver starts with something, aStringOrChar.
+     If the argument is empty, true is returned.
+     Notice, that this is similar to, but slightly different from VW's and Squeak's beginsWith:,
+     which are both inconsistent w.r.t. an empty argument."
+
+%{  /* NOCONTEXT */
+    int len1, len2;
+    REGISTER unsigned char *src1, *src2;
+    unsigned char c;
+    REGISTER OBJ slf = self;
+
+    if (__qIsByteArrayLike(slf) &&__isByteArrayLike(aByteOrByteArray)) {
+        src1 = __byteArrayVal(slf);
+        src2 = __byteArrayVal(aByteOrByteArray);
+
+        if (src1[0] != src2[0]) {
+            if (__qSize(aByteOrByteArray) == OHDR_SIZE) {
+                RETURN (true);
+            }
+            RETURN ( false );
+        }
+
+        len1 = __qSize(slf);
+        len2 = __qSize(aByteOrByteArray);
+        if (len1 < len2) {
+            RETURN ( false );
+        }
+
+# ifdef UINT64
+        while (len2 > (OHDR_SIZE+sizeof(UINT64))) {
+            if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) {
+                RETURN (false);
+            }
+            len2 -= sizeof(UINT64);
+            src1 += sizeof(UINT64);
+            src2 += sizeof(UINT64);
+        }
+# else
+#  ifdef __UNROLL_LOOPS__
+        while (len2 > (OHDR_SIZE+sizeof(INT)*4)) {
+            if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
+                RETURN (false);
+            }
+            if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) {
+                RETURN (false);
+            }
+            if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) {
+                RETURN (false);
+            }
+            if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) {
+                RETURN (false);
+            }
+            len2 -= sizeof(INT)*4;
+            src1 += sizeof(INT)*4;
+            src2 += sizeof(INT)*4;
+        }
+#  endif /* __UNROLL_LOOPS__ */
+# endif /* UINT64 */
+
+        while (len2 > (OHDR_SIZE+sizeof(INT))) {
+            if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
+                RETURN (false);
+            }
+            len2 -= sizeof(INT);
+            src1 += sizeof(INT);
+            src2 += sizeof(INT);
+        }
+
+        for ( ; len2 > (OHDR_SIZE+sizeof(INT)); len2++) {
+            if (*src1++ != *src2++) {
+                RETURN (false);
+            }
+        }    
+        RETURN (true);
+    }
+    if (__isSmallInteger(aByteOrByteArray)) {
+        int val = __intVal(aByteOrByteArray);
+        if (__byteArraySize(slf) > 0) {
+            RETURN ( (__byteArrayVal(slf)[0] == val) ? true : false);
+        }
+        RETURN ( false );
+    }
+%}.
+    ^ super startsWith:aByteOrByteArray
+
+    "
+     #[1 2 3 4 5 6 7 8 9 10] startsWith:#[ 1 2 3 4 5]
+     #[1 2 3 4 5 6 7 8 9 10] startsWith:#[ 0 1 2 3 4 5]
+     #[1 2 3 4 5 6 7 8 9 10] startsWith:#(1 2 3 4 5)
+     #[1 2 3 4 5 6 7 8 9 10] startsWith:1
+     #[1 2 3 4 5 6 7 8 9 10] startsWith:2
+    "
+!
+
 usageCounts
     "return an array filled with value-counts -
      This is needed in the bitmap/image classes to get info on color usage.
@@ -3063,6 +3157,7 @@
     "
 ! !
 
+
 !ByteArray methodsFor:'testing'!
 
 isByteArray
@@ -3087,7 +3182,6 @@
     "Modified: 22.4.1996 / 12:55:30 / cg"
 ! !
 
-
 !ByteArray class methodsFor:'documentation'!
 
 version
--- a/HashStream.st	Sat Apr 23 09:05:39 2016 +0100
+++ b/HashStream.st	Mon Apr 25 10:19:26 2016 +0100
@@ -186,15 +186,15 @@
 
 !HashStream class methodsFor:'utilities'!
 
-cryptBlock:aStringOrByteArray from:srcIdx into:resultOrNil startingAt:dstIdx encrypt:encryptMode
+cryptBlock:aStringOrByteArray from:srcIdx to:srcEndOrNil into:resultOrNil startingAt:dstIdx encrypt:encryptMode
     "one-way encryption of aStringOrByteArray.
-     Used when a HashStream is used as the block copher with OFB or CTR mode.
+     Used when a HashStream is used as the block cipher with OFB or CTR mode.
 
      encryptMode is ignored here."
 
     |hashValue|
 
-    srcIdx == 1 ifTrue:[
+    (srcIdx == 1 and:[srcEndOrNil isNil]) ifTrue:[
         hashValue := self hashValueOf:aStringOrByteArray.
     ] ifFalse:[
         |bytesToEncrypt|