changeset 18655 | 57469de23fac |
parent 18611 | fca966d5e383 |
child 18665 | fd08070e4467 |
18654:12e555d89149 | 18655:57469de23fac |
---|---|
198 |
198 |
199 "size := self size min:aByteArray size" |
199 "size := self size min:aByteArray size" |
200 size := self size. |
200 size := self size. |
201 size1 := aByteArray size. |
201 size1 := aByteArray size. |
202 size1 < size ifTrue:[ |
202 size1 < size ifTrue:[ |
203 size := size1. |
203 size := size1. |
204 ]. |
204 ]. |
205 |
205 |
206 ^ self copy |
206 ^ self copy |
207 bitXorBytesFrom:1 to:size with:aByteArray startingAt:1; |
207 bitXorBytesFrom:1 to:size with:aByteArray startingAt:1; |
208 yourself. |
208 yourself. |
209 |
209 |
210 " |
210 " |
211 #[0 1 2 3 4] bitXor:#[0 1 2 3 4] |
211 #[0 1 2 3 4] bitXor:#[0 1 2 3 4] |
212 #[0 1 2 3 4] bitXor:#[0 1 2 3] |
212 #[0 1 2 3 4] bitXor:#[0 1 2 3] |
213 " |
213 " |
214 ! ! |
214 ! ! |
215 |
215 |
216 !ByteArray methodsFor:'Compatibility-VW'! |
216 !ByteArray methodsFor:'Compatibility-VW'! |
217 |
217 |
1062 This is also in Squeak." |
1062 This is also in Squeak." |
1063 |
1063 |
1064 ^ self asIntegerMSB:true |
1064 ^ self asIntegerMSB:true |
1065 |
1065 |
1066 " |
1066 " |
1067 #[ 2 ] asInteger hexPrintString |
1067 #[ 2 ] asInteger hexPrintString |
1068 #[ 16r1 16r2 ] asInteger hexPrintString |
1068 #[ 16r1 16r2 ] asInteger hexPrintString |
1069 #[4 0 0 0 0 0 0 0] asInteger hexPrintString |
1069 #[4 0 0 0 0 0 0 0] asInteger hexPrintString |
1070 " |
1070 " |
1071 ! |
1071 ! |
1072 |
1072 |
1073 asIntegerMSB:isMSBFirst |
1073 asIntegerMSB:isMSBFirst |
1074 "convert myself to an integer - the first byte is most significant. |
1074 "convert myself to an integer - the first byte is most significant. |
1075 This is also in Squeak." |
1075 This is also in Squeak." |
1076 |
1076 |
1077 ^ (LargeInteger digitBytes:self MSB:isMSBFirst) compressed |
1077 ^ (LargeInteger digitBytes:self MSB:isMSBFirst) compressed |
1078 |
1078 |
1079 " |
1079 " |
1080 (#[ 2 ] asIntegerMSB:true) hexPrintString |
1080 (#[ 2 ] asIntegerMSB:true) hexPrintString |
1081 (#[ 16r1 16r2 ] asIntegerMSB:true) hexPrintString |
1081 (#[ 16r1 16r2 ] asIntegerMSB:true) hexPrintString |
1082 (#[ 16r1 16r2 ] asIntegerMSB:false) hexPrintString |
1082 (#[ 16r1 16r2 ] asIntegerMSB:false) hexPrintString |
1083 (#[4 0 0 0 0 0 0 0] asIntegerMSB:true) hexPrintString |
1083 (#[4 0 0 0 0 0 0 0] asIntegerMSB:true) hexPrintString |
1084 " |
1084 " |
1085 ! |
1085 ! |
1086 |
1086 |
1087 asPackedString |
1087 asPackedString |
1088 "ST-80 compatibility: encode the receiver into an ascii String |
1088 "ST-80 compatibility: encode the receiver into an ascii String |
1107 outStream := WriteStream on:(String new:((self size + 2) * 4 // 3)). |
1107 outStream := WriteStream on:(String new:((self size + 2) * 4 // 3)). |
1108 index := 1. |
1108 index := 1. |
1109 stop := self size. |
1109 stop := self size. |
1110 |
1110 |
1111 stop > 100 ifTrue:[ |
1111 stop > 100 ifTrue:[ |
1112 "/ cg: |
1112 "/ cg: |
1113 "/ initial lineBreak |
1113 "/ initial lineBreak |
1114 outStream cr. |
1114 outStream cr. |
1115 ]. |
1115 ]. |
1116 cpl := 0. |
1116 cpl := 0. |
1117 |
1117 |
1118 [index <= stop] whileTrue:[ |
1118 [index <= stop] whileTrue:[ |
1119 "take 3 source bytes" |
1119 "take 3 source bytes" |
1120 n := (self at:index) bitShift:16. |
1120 n := (self at:index) bitShift:16. |
1121 (index < stop) ifTrue:[ |
1121 (index < stop) ifTrue:[ |
1122 nextIndex := index + 1. |
1122 nextIndex := index + 1. |
1123 n := n bitOr:((self at:nextIndex) bitShift:8). |
1123 n := n bitOr:((self at:nextIndex) bitShift:8). |
1124 (nextIndex < stop) ifTrue:[ |
1124 (nextIndex < stop) ifTrue:[ |
1125 n := n bitOr:(self at:(index + 2)). |
1125 n := n bitOr:(self at:(index + 2)). |
1126 ]. |
1126 ]. |
1127 ]. |
1127 ]. |
1128 index := index + 3. |
1128 index := index + 3. |
1129 |
1129 |
1130 "took me a while to find that one out ..." |
1130 "took me a while to find that one out ..." |
1131 n := n bitXor:16r820820. |
1131 n := n bitXor:16r820820. |
1132 |
1132 |
1133 outStream nextPut:(Character value:((n bitShift:-18) bitAnd:16r3F) + 32). |
1133 outStream nextPut:(Character value:((n bitShift:-18) bitAnd:16r3F) + 32). |
1134 outStream nextPut:(Character value:((n bitShift:-12) bitAnd:16r3F) + 32). |
1134 outStream nextPut:(Character value:((n bitShift:-12) bitAnd:16r3F) + 32). |
1135 outStream nextPut:(Character value:((n bitShift:-6) bitAnd:16r3F) + 32). |
1135 outStream nextPut:(Character value:((n bitShift:-6) bitAnd:16r3F) + 32). |
1136 outStream nextPut:(Character value:(n bitAnd:16r3F) + 32). |
1136 outStream nextPut:(Character value:(n bitAnd:16r3F) + 32). |
1137 |
1137 |
1138 "/ cg: |
1138 "/ cg: |
1139 "/ lineBreak after every 120 characters |
1139 "/ lineBreak after every 120 characters |
1140 "/ fromPackedString will ignore those |
1140 "/ fromPackedString will ignore those |
1141 cpl := cpl + 4. |
1141 cpl := cpl + 4. |
1142 cpl >= 120 ifTrue:[ |
1142 cpl >= 120 ifTrue:[ |
1143 outStream cr. |
1143 outStream cr. |
1144 cpl := 0. |
1144 cpl := 0. |
1145 ]. |
1145 ]. |
1146 ]. |
1146 ]. |
1147 (mod := stop \\ 3) ~~ 0 ifTrue:[ |
1147 (mod := stop \\ 3) ~~ 0 ifTrue:[ |
1148 outStream backStep. |
1148 outStream backStep. |
1149 outStream nextPut:(Character value:(mod + 96)). |
1149 outStream nextPut:(Character value:(mod + 96)). |
1150 ]. |
1150 ]. |
1151 ^ outStream contents |
1151 ^ outStream contents |
1152 |
1152 |
1153 " |
1153 " |
1154 #[ 16r00 16r01 16r02 16r04 16r08 16r10 16r20 16r40 16r80 ] asPackedString |
1154 #[ 16r00 16r01 16r02 16r04 16r08 16r10 16r20 16r40 16r80 ] asPackedString |
1535 "perform a special case of an aligned bitBlit operation. |
1535 "perform a special case of an aligned bitBlit operation. |
1536 Bytes in the receiver from dstStart to dstEnd are destructively replaced by the result |
1536 Bytes in the receiver from dstStart to dstEnd are destructively replaced by the result |
1537 of some logical operation, as specified by the ruleSymbol. |
1537 of some logical operation, as specified by the ruleSymbol. |
1538 SourceBytes are fetched starting at sourceOffset. |
1538 SourceBytes are fetched starting at sourceOffset. |
1539 Valid rule symbols are: |
1539 Valid rule symbols are: |
1540 #copy - trivial; same as replaceBytesFrom:to:with:startingAt: |
1540 #copy - trivial; same as replaceBytesFrom:to:with:startingAt: |
1541 #bitXor: - xoring; byte[dI] = byte[dI] bitXor:(srcByte[sI]) |
1541 #bitXor: - xoring; byte[dI] = byte[dI] bitXor:(srcByte[sI]) |
1542 #bitAnd: - anding; byte[dI] = byte[dI] bitAnd:(srcByte[sI]) |
1542 #bitAnd: - anding; byte[dI] = byte[dI] bitAnd:(srcByte[sI]) |
1543 #bitOr: - oring; byte[dI] = byte[dI] bitOr:(srcByte[sI]) |
1543 #bitOr: - oring; byte[dI] = byte[dI] bitOr:(srcByte[sI]) |
1544 #+ - adding; byte[dI] = (byte[dI] + (srcByte[sI])) mod: 256 |
1544 #+ - adding; byte[dI] = (byte[dI] + (srcByte[sI])) mod: 256 |
1545 #- - subtract; byte[dI] = (byte[dI] - (srcByte[sI])) mod: 256 |
1545 #- - subtract; byte[dI] = (byte[dI] - (srcByte[sI])) mod: 256 |
1546 Warning: this is a destructive operation - elements in the receiver are overwritten. |
1546 Warning: this is a destructive operation - elements in the receiver are overwritten. |
1547 " |
1547 " |
1548 |
1548 |
1549 |srcIdx| |
1549 |srcIdx| |
1550 |
1550 |
1552 if ((__isByteArrayLike(sourceBytes)) |
1552 if ((__isByteArrayLike(sourceBytes)) |
1553 && (__qClass(self) == ByteArray) |
1553 && (__qClass(self) == ByteArray) |
1554 && __isSmallInteger(dstStart) |
1554 && __isSmallInteger(dstStart) |
1555 && __isSmallInteger(dstEnd) |
1555 && __isSmallInteger(dstEnd) |
1556 && __isSmallInteger(sourceStart)) { |
1556 && __isSmallInteger(sourceStart)) { |
1557 unsigned char *srcP = __ByteArrayInstPtr(sourceBytes)->ba_element; |
1557 unsigned char *srcP = __ByteArrayInstPtr(sourceBytes)->ba_element; |
1558 unsigned char *dstP = __ByteArrayInstPtr(self)->ba_element; |
1558 unsigned char *dstP = __ByteArrayInstPtr(self)->ba_element; |
1559 int srcLen = __byteArraySize(sourceBytes); |
1559 int srcLen = __byteArraySize(sourceBytes); |
1560 int dstLen = __byteArraySize(self); |
1560 int dstLen = __byteArraySize(self); |
1561 int __srcStart = __intVal(sourceStart); |
1561 int __srcStart = __intVal(sourceStart); |
1562 int __dstStart = __intVal(dstStart); |
1562 int __dstStart = __intVal(dstStart); |
1563 int count = __intVal(dstEnd) - __dstStart + 1; |
1563 int count = __intVal(dstEnd) - __dstStart + 1; |
1564 |
1564 |
1565 if ((__dstStart >= 1) |
1565 if ((__dstStart >= 1) |
1566 && (__srcStart >= 1) |
1566 && (__srcStart >= 1) |
1567 && ((__dstStart + count - 1) <= dstLen) |
1567 && ((__dstStart + count - 1) <= dstLen) |
1568 && ((__srcStart + count - 1) <= srcLen)) { |
1568 && ((__srcStart + count - 1) <= srcLen)) { |
1569 srcP += __srcStart - 1; |
1569 srcP += __srcStart - 1; |
1570 dstP += __dstStart - 1; |
1570 dstP += __dstStart - 1; |
1571 |
1571 |
1572 #define OP_LOOP_BYTES(OP) \ |
1572 #define OP_LOOP_BYTES(OP) \ |
1573 while (count >= 4) { \ |
1573 while (count >= 4) { \ |
1574 (dstP[0]) OP (srcP[0]); \ |
1574 (dstP[0]) OP (srcP[0]); \ |
1575 (dstP[1]) OP (srcP[1]); \ |
1575 (dstP[1]) OP (srcP[1]); \ |
1576 (dstP[2]) OP (srcP[2]); \ |
1576 (dstP[2]) OP (srcP[2]); \ |
1577 (dstP[3]) OP (srcP[3]); \ |
1577 (dstP[3]) OP (srcP[3]); \ |
1578 srcP += 4; \ |
1578 srcP += 4; \ |
1579 dstP += 4; \ |
1579 dstP += 4; \ |
1580 count -= 4; \ |
1580 count -= 4; \ |
1581 } \ |
1581 } \ |
1582 while (count > 0) { \ |
1582 while (count > 0) { \ |
1583 *dstP OP (*srcP); \ |
1583 *dstP OP (*srcP); \ |
1584 srcP++; \ |
1584 srcP++; \ |
1585 dstP++; \ |
1585 dstP++; \ |
1586 count--; \ |
1586 count--; \ |
1587 } |
1587 } |
1588 |
1588 |
1589 #define OP_LOOP(OP) \ |
1589 #define OP_LOOP(OP) \ |
1590 while (count >= 16) { \ |
1590 while (count >= 16) { \ |
1591 ((unsigned int *)dstP)[0] OP (((unsigned int *)srcP)[0]); \ |
1591 ((unsigned int *)dstP)[0] OP (((unsigned int *)srcP)[0]); \ |
1592 ((unsigned int *)dstP)[1] OP (((unsigned int *)srcP)[1]); \ |
1592 ((unsigned int *)dstP)[1] OP (((unsigned int *)srcP)[1]); \ |
1593 ((unsigned int *)dstP)[2] OP (((unsigned int *)srcP)[2]); \ |
1593 ((unsigned int *)dstP)[2] OP (((unsigned int *)srcP)[2]); \ |
1594 ((unsigned int *)dstP)[3] OP (((unsigned int *)srcP)[3]); \ |
1594 ((unsigned int *)dstP)[3] OP (((unsigned int *)srcP)[3]); \ |
1595 srcP += 16; \ |
1595 srcP += 16; \ |
1596 dstP += 16; \ |
1596 dstP += 16; \ |
1597 count -= 16; \ |
1597 count -= 16; \ |
1598 } \ |
1598 } \ |
1599 while (count >= 4) { \ |
1599 while (count >= 4) { \ |
1600 ((unsigned int *)dstP)[0] OP (((unsigned int *)srcP)[0]); \ |
1600 ((unsigned int *)dstP)[0] OP (((unsigned int *)srcP)[0]); \ |
1601 srcP += 4; \ |
1601 srcP += 4; \ |
1602 dstP += 4; \ |
1602 dstP += 4; \ |
1603 count -= 4; \ |
1603 count -= 4; \ |
1604 } \ |
1604 } \ |
1605 while (count > 0) { \ |
1605 while (count > 0) { \ |
1606 *dstP OP (*srcP); \ |
1606 *dstP OP (*srcP); \ |
1607 srcP++; \ |
1607 srcP++; \ |
1608 dstP++; \ |
1608 dstP++; \ |
1609 count--; \ |
1609 count--; \ |
1610 } |
1610 } |
1611 |
1611 |
1612 |
1612 |
1613 if (ruleSymbol == @symbol(bitXor:)) { |
1613 if (ruleSymbol == @symbol(bitXor:)) { |
1614 OP_LOOP( ^= ) |
1614 OP_LOOP( ^= ) |
1615 RETURN (self); |
1615 RETURN (self); |
1616 } |
1616 } |
1617 if (ruleSymbol == @symbol(bitXorNot:)) { |
1617 if (ruleSymbol == @symbol(bitXorNot:)) { |
1618 OP_LOOP( ^=~ ) |
1618 OP_LOOP( ^=~ ) |
1619 RETURN (self); |
1619 RETURN (self); |
1620 } |
1620 } |
1621 if (ruleSymbol == @symbol(bitAnd:)) { |
1621 if (ruleSymbol == @symbol(bitAnd:)) { |
1622 OP_LOOP( &= ) |
1622 OP_LOOP( &= ) |
1623 RETURN (self); |
1623 RETURN (self); |
1624 } |
1624 } |
1625 if (ruleSymbol == @symbol(bitAndNot:)) { |
1625 if (ruleSymbol == @symbol(bitAndNot:)) { |
1626 OP_LOOP( &=~ ) |
1626 OP_LOOP( &=~ ) |
1627 RETURN (self); |
1627 RETURN (self); |
1628 } |
1628 } |
1629 if (ruleSymbol == @symbol(bitOr:)) { |
1629 if (ruleSymbol == @symbol(bitOr:)) { |
1630 OP_LOOP( |= ) |
1630 OP_LOOP( |= ) |
1631 RETURN (self); |
1631 RETURN (self); |
1632 } |
1632 } |
1633 if (ruleSymbol == @symbol(bitOrNot:)) { |
1633 if (ruleSymbol == @symbol(bitOrNot:)) { |
1634 OP_LOOP( |=~ ) |
1634 OP_LOOP( |=~ ) |
1635 RETURN (self); |
1635 RETURN (self); |
1636 } |
1636 } |
1637 if (ruleSymbol == @symbol(copy)) { |
1637 if (ruleSymbol == @symbol(copy)) { |
1638 OP_LOOP( = ) |
1638 OP_LOOP( = ) |
1639 RETURN (self); |
1639 RETURN (self); |
1640 } |
1640 } |
1641 if (ruleSymbol == @symbol(copyNot)) { |
1641 if (ruleSymbol == @symbol(copyNot)) { |
1642 OP_LOOP( =~ ) |
1642 OP_LOOP( =~ ) |
1643 RETURN (self); |
1643 RETURN (self); |
1644 } |
1644 } |
1645 if (ruleSymbol == @symbol(+)) { |
1645 if (ruleSymbol == @symbol(+)) { |
1646 OP_LOOP_BYTES( += ) |
1646 OP_LOOP_BYTES( += ) |
1647 RETURN (self); |
1647 RETURN (self); |
1648 } |
1648 } |
1649 if (ruleSymbol == @symbol(-)) { |
1649 if (ruleSymbol == @symbol(-)) { |
1650 OP_LOOP_BYTES( -= ) |
1650 OP_LOOP_BYTES( -= ) |
1651 RETURN (self); |
1651 RETURN (self); |
1652 } |
1652 } |
1653 } |
1653 } |
1654 } |
1654 } |
1655 #undef OP_LOOP_BYTES |
1655 #undef OP_LOOP_BYTES |
1656 #undef OP_LOOP |
1656 #undef OP_LOOP |
1657 |
1657 |
1658 %}. |
1658 %}. |
1659 ruleSymbol == #copy ifTrue:[ |
1659 ruleSymbol == #copy ifTrue:[ |
1660 self replaceFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart. |
1660 self replaceFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart. |
1661 ^ self |
1661 ^ self |
1662 ]. |
1662 ]. |
1663 |
1663 |
1664 srcIdx := sourceStart. |
1664 srcIdx := sourceStart. |
1665 dstStart to:dstEnd do:[:dstIdx | |
1665 dstStart to:dstEnd do:[:dstIdx | |
1666 self at:dstIdx put:((self at:dstIdx) perform:ruleSymbol with:(sourceBytes at:srcIdx)). |
1666 self at:dstIdx put:((self at:dstIdx) perform:ruleSymbol with:(sourceBytes at:srcIdx)). |
1667 srcIdx := srcIdx + 1. |
1667 srcIdx := srcIdx + 1. |
1668 ]. |
1668 ]. |
1669 |
1669 |
1670 " |
1670 " |
1671 #[1 2 3 4 5 6 7 8] |
1671 #[1 2 3 4 5 6 7 8] |
1672 bitBlitBytesFrom:1 to:3 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#bitXor: |
1672 bitBlitBytesFrom:1 to:3 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#bitXor: |
1673 #[1 2 3 4 5 6 7 8] |
1673 #[1 2 3 4 5 6 7 8] |
1674 bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#bitXor: |
1674 bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#bitXor: |
1675 #[1 2 3 4 5 6 7 8] |
1675 #[1 2 3 4 5 6 7 8] |
1676 bitBlitBytesFrom:1 to:8 with:#[1 1 1 1 1 1 1 1] startingAt:1 rule:#bitAnd: |
1676 bitBlitBytesFrom:1 to:8 with:#[1 1 1 1 1 1 1 1] startingAt:1 rule:#bitAnd: |
1677 #[1 2 3 4 5 6 7 8] |
1677 #[1 2 3 4 5 6 7 8] |
1678 bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#+ |
1678 bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#+ |
1679 #[255 0 0 0 0 0 0 0] |
1679 #[255 0 0 0 0 0 0 0] |
1680 bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#+ |
1680 bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#+ |
1681 #[1 2 3 4 5 6 7 8] |
1681 #[1 2 3 4 5 6 7 8] |
1682 bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 1 1 1 1] startingAt:1 rule:#+ |
1682 bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 1 1 1 1] startingAt:1 rule:#+ |
1683 #[1 2 3 4 5 6 7 8] |
1683 #[1 2 3 4 5 6 7 8] |
1684 bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 2 2 2 2] startingAt:5 rule:#+ |
1684 bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 2 2 2 2] startingAt:5 rule:#+ |
1685 #[1 2 3 4 5 6 7 8] |
1685 #[1 2 3 4 5 6 7 8] |
1686 bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 2 2 2 2] startingAt:5 rule:#copyNot |
1686 bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 2 2 2 2] startingAt:5 rule:#copyNot |
1687 |
1687 |
1688 #[1 2 3 4 5 6 7 8] |
1688 #[1 2 3 4 5 6 7 8] |
1689 bitBlitBytesFrom:1 to:8 with:(1 to:8) startingAt:1 rule:#+ |
1689 bitBlitBytesFrom:1 to:8 with:(1 to:8) startingAt:1 rule:#+ |
1690 " |
1690 " |
1691 ! |
1691 ! |
1692 |
1692 |
1693 bitBlitBytesFrom:dstStart to:dstEnd withConstant:sourceByte rule:ruleSymbol |
1693 bitBlitBytesFrom:dstStart to:dstEnd withConstant:sourceByte rule:ruleSymbol |
1694 "perform a special case of an aligned bitBlit operation. |
1694 "perform a special case of an aligned bitBlit operation. |
1695 Bytes in the receiver from dstStart to dstEnd are destructively replaced by the result |
1695 Bytes in the receiver from dstStart to dstEnd are destructively replaced by the result |
1696 of some logical operation, as specified by the ruleSymbol. |
1696 of some logical operation, as specified by the ruleSymbol. |
1697 Valid rule symbols are: |
1697 Valid rule symbols are: |
1698 #copy - trivial; same as from:to:put: |
1698 #copy - trivial; same as from:to:put: |
1699 #bitXor: - xoring; byte[dI] = byte[dI] bitXor:sourceConst |
1699 #bitXor: - xoring; byte[dI] = byte[dI] bitXor:sourceConst |
1700 #bitAnd: - anding; byte[dI] = byte[dI] bitAnd:sourceConst |
1700 #bitAnd: - anding; byte[dI] = byte[dI] bitAnd:sourceConst |
1701 #bitOr: - oring; byte[dI] = byte[dI] bitOr:sourceConst |
1701 #bitOr: - oring; byte[dI] = byte[dI] bitOr:sourceConst |
1702 #+ - adding; byte[dI] = (byte[dI] + sourceConst) mod: 256 |
1702 #+ - adding; byte[dI] = (byte[dI] + sourceConst) mod: 256 |
1703 #- - subtract; byte[dI] = (byte[dI] - sourceConst) mod: 256 |
1703 #- - subtract; byte[dI] = (byte[dI] - sourceConst) mod: 256 |
1704 Warning: this is a destructive operation - elements in the receiver are overwritten. |
1704 Warning: this is a destructive operation - elements in the receiver are overwritten. |
1705 " |
1705 " |
1706 |
1706 |
1707 |srcIdx| |
1707 |srcIdx| |
1708 |
1708 |
1709 %{ |
1709 %{ |
1710 if ((__qClass(self) == ByteArray) |
1710 if ((__qClass(self) == ByteArray) |
1711 && __isSmallInteger(dstStart) |
1711 && __isSmallInteger(dstStart) |
1712 && __isSmallInteger(dstEnd) |
1712 && __isSmallInteger(dstEnd) |
1713 && __isSmallInteger(sourceByte)) { |
1713 && __isSmallInteger(sourceByte)) { |
1714 unsigned char srcByte = __intVal(sourceByte); |
1714 unsigned char srcByte = __intVal(sourceByte); |
1715 unsigned srcWord; |
1715 unsigned srcWord; |
1716 unsigned char *dstP = __ByteArrayInstPtr(self)->ba_element; |
1716 unsigned char *dstP = __ByteArrayInstPtr(self)->ba_element; |
1717 int dstLen = __byteArraySize(self); |
1717 int dstLen = __byteArraySize(self); |
1718 int __dstStart = __intVal(dstStart); |
1718 int __dstStart = __intVal(dstStart); |
1719 int count = __intVal(dstEnd) - __dstStart + 1; |
1719 int count = __intVal(dstEnd) - __dstStart + 1; |
1720 |
1720 |
1721 srcWord = (srcByte << 8) | srcByte; |
1721 srcWord = (srcByte << 8) | srcByte; |
1722 srcWord = (srcWord << 16) | srcWord; |
1722 srcWord = (srcWord << 16) | srcWord; |
1723 if ((__dstStart >= 1) |
1723 if ((__dstStart >= 1) |
1724 && ((__dstStart + count - 1) <= dstLen)) { |
1724 && ((__dstStart + count - 1) <= dstLen)) { |
1725 dstP += __dstStart - 1; |
1725 dstP += __dstStart - 1; |
1726 |
1726 |
1727 #define OP_LOOP_BYTES(OP) \ |
1727 #define OP_LOOP_BYTES(OP) \ |
1728 while (count >= 4) { \ |
1728 while (count >= 4) { \ |
1729 dstP[0] OP srcByte; \ |
1729 dstP[0] OP srcByte; \ |
1730 dstP[1] OP srcByte; \ |
1730 dstP[1] OP srcByte; \ |
1731 dstP[2] OP srcByte; \ |
1731 dstP[2] OP srcByte; \ |
1732 dstP[3] OP srcByte; \ |
1732 dstP[3] OP srcByte; \ |
1733 dstP += 4; \ |
1733 dstP += 4; \ |
1734 count -= 4; \ |
1734 count -= 4; \ |
1735 } \ |
1735 } \ |
1736 while (count > 0) { \ |
1736 while (count > 0) { \ |
1737 *dstP OP srcByte; \ |
1737 *dstP OP srcByte; \ |
1738 dstP++; \ |
1738 dstP++; \ |
1739 count--; \ |
1739 count--; \ |
1740 } |
1740 } |
1741 |
1741 |
1742 #define OP_LOOP_INT32(OP) \ |
1742 #define OP_LOOP_INT32(OP) \ |
1743 while (count >= 16) { \ |
1743 while (count >= 16) { \ |
1744 ((unsigned int *)dstP)[0] OP srcWord; \ |
1744 ((unsigned int *)dstP)[0] OP srcWord; \ |
1745 ((unsigned int *)dstP)[1] OP srcWord; \ |
1745 ((unsigned int *)dstP)[1] OP srcWord; \ |
1746 ((unsigned int *)dstP)[2] OP srcWord; \ |
1746 ((unsigned int *)dstP)[2] OP srcWord; \ |
1747 ((unsigned int *)dstP)[3] OP srcWord; \ |
1747 ((unsigned int *)dstP)[3] OP srcWord; \ |
1748 dstP += 16; \ |
1748 dstP += 16; \ |
1749 count -= 16; \ |
1749 count -= 16; \ |
1750 } \ |
1750 } \ |
1751 |
1751 |
1752 #define OP_LOOP(OP) \ |
1752 #define OP_LOOP(OP) \ |
1753 OP_LOOP_INT32(OP) \ |
1753 OP_LOOP_INT32(OP) \ |
1754 while (count >= 4) { \ |
1754 while (count >= 4) { \ |
1755 ((unsigned int *)dstP)[0] OP srcWord; \ |
1755 ((unsigned int *)dstP)[0] OP srcWord; \ |
1756 dstP += 4; \ |
1756 dstP += 4; \ |
1757 count -= 4; \ |
1757 count -= 4; \ |
1758 } \ |
1758 } \ |
1759 while (count > 0) { \ |
1759 while (count > 0) { \ |
1760 *dstP OP srcByte; \ |
1760 *dstP OP srcByte; \ |
1761 dstP++; \ |
1761 dstP++; \ |
1762 count--; \ |
1762 count--; \ |
1763 } |
1763 } |
1764 |
1764 |
1765 |
1765 |
1766 if (ruleSymbol == @symbol(bitXor:)) { |
1766 if (ruleSymbol == @symbol(bitXor:)) { |
1767 OP_LOOP( ^= ) |
1767 OP_LOOP( ^= ) |
1768 RETURN (self); |
1768 RETURN (self); |
1769 } |
1769 } |
1770 if (ruleSymbol == @symbol(bitXorNot:)) { |
1770 if (ruleSymbol == @symbol(bitXorNot:)) { |
1771 OP_LOOP( ^=~ ) |
1771 OP_LOOP( ^=~ ) |
1772 RETURN (self); |
1772 RETURN (self); |
1773 } |
1773 } |
1774 if (ruleSymbol == @symbol(bitAnd:)) { |
1774 if (ruleSymbol == @symbol(bitAnd:)) { |
1775 OP_LOOP( &= ) |
1775 OP_LOOP( &= ) |
1776 RETURN (self); |
1776 RETURN (self); |
1777 } |
1777 } |
1778 if (ruleSymbol == @symbol(bitAndNot:)) { |
1778 if (ruleSymbol == @symbol(bitAndNot:)) { |
1779 OP_LOOP( &=~ ) |
1779 OP_LOOP( &=~ ) |
1780 RETURN (self); |
1780 RETURN (self); |
1781 } |
1781 } |
1782 if (ruleSymbol == @symbol(bitOr:)) { |
1782 if (ruleSymbol == @symbol(bitOr:)) { |
1783 OP_LOOP( |= ) |
1783 OP_LOOP( |= ) |
1784 RETURN (self); |
1784 RETURN (self); |
1785 } |
1785 } |
1786 if (ruleSymbol == @symbol(bitOrNot:)) { |
1786 if (ruleSymbol == @symbol(bitOrNot:)) { |
1787 OP_LOOP( |=~ ) |
1787 OP_LOOP( |=~ ) |
1788 RETURN (self); |
1788 RETURN (self); |
1789 } |
1789 } |
1790 if (ruleSymbol == @symbol(copy)) { |
1790 if (ruleSymbol == @symbol(copy)) { |
1791 OP_LOOP( = ) |
1791 OP_LOOP( = ) |
1792 RETURN (self); |
1792 RETURN (self); |
1793 } |
1793 } |
1794 if (ruleSymbol == @symbol(copyNot)) { |
1794 if (ruleSymbol == @symbol(copyNot)) { |
1795 OP_LOOP( =~ ) |
1795 OP_LOOP( =~ ) |
1796 RETURN (self); |
1796 RETURN (self); |
1797 } |
1797 } |
1798 if (ruleSymbol == @symbol(+)) { |
1798 if (ruleSymbol == @symbol(+)) { |
1799 OP_LOOP_BYTES( += ) |
1799 OP_LOOP_BYTES( += ) |
1800 RETURN (self); |
1800 RETURN (self); |
1801 } |
1801 } |
1802 if (ruleSymbol == @symbol(-)) { |
1802 if (ruleSymbol == @symbol(-)) { |
1803 OP_LOOP_BYTES( -= ) |
1803 OP_LOOP_BYTES( -= ) |
1804 RETURN (self); |
1804 RETURN (self); |
1805 } |
1805 } |
1806 } |
1806 } |
1807 } |
1807 } |
1808 #undef OP_LOOP_BYTES |
1808 #undef OP_LOOP_BYTES |
1809 #undef OP_LOOP |
1809 #undef OP_LOOP |
1810 %}. |
1810 %}. |
1811 ruleSymbol == #copy ifTrue:[ |
1811 ruleSymbol == #copy ifTrue:[ |
1812 self from:dstStart to:dstEnd put:sourceByte. |
1812 self from:dstStart to:dstEnd put:sourceByte. |
1813 ^ self |
1813 ^ self |
1814 ]. |
1814 ]. |
1815 |
1815 |
1816 dstStart to:dstEnd do:[:dstIdx | |
1816 dstStart to:dstEnd do:[:dstIdx | |
1817 self at:dstIdx put:((self at:dstIdx) perform:ruleSymbol with:sourceByte). |
1817 self at:dstIdx put:((self at:dstIdx) perform:ruleSymbol with:sourceByte). |
1818 ]. |
1818 ]. |
1819 |
1819 |
1820 " |
1820 " |
1821 #[1 2 3 4 5 6 7 8] |
1821 #[1 2 3 4 5 6 7 8] |
1822 bitBlitBytesFrom:1 to:3 withConstant:1 rule:#bitXor: |
1822 bitBlitBytesFrom:1 to:3 withConstant:1 rule:#bitXor: |
1823 #[1 2 3 4 5 6 7 8] |
1823 #[1 2 3 4 5 6 7 8] |
1824 bitBlitBytesFrom:1 to:8 withConstant:1 rule:#bitXor: |
1824 bitBlitBytesFrom:1 to:8 withConstant:1 rule:#bitXor: |
1825 #[1 2 3 4 5 6 7 8] |
1825 #[1 2 3 4 5 6 7 8] |
1826 bitBlitBytesFrom:1 to:8 withConstant:1 rule:#bitAnd: |
1826 bitBlitBytesFrom:1 to:8 withConstant:1 rule:#bitAnd: |
1827 #[1 2 3 4 5 6 7 8] |
1827 #[1 2 3 4 5 6 7 8] |
1828 bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+ |
1828 bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+ |
1829 #[255 0 0 0 0 0 0 0] |
1829 #[255 0 0 0 0 0 0 0] |
1830 bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+ |
1830 bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+ |
1831 #[1 2 3 4 5 6 7 8] |
1831 #[1 2 3 4 5 6 7 8] |
1832 bitBlitBytesFrom:1 to:4 withConstant:1 rule:#+ |
1832 bitBlitBytesFrom:1 to:4 withConstant:1 rule:#+ |
1833 #[1 2 3 4 5 6 7 8] |
1833 #[1 2 3 4 5 6 7 8] |
1834 bitBlitBytesFrom:1 to:4 withConstant:1 rule:#- |
1834 bitBlitBytesFrom:1 to:4 withConstant:1 rule:#- |
1835 #[1 2 3 4 5 6 7 8] |
1835 #[1 2 3 4 5 6 7 8] |
1836 bitBlitBytesFrom:1 to:4 withConstant:1 rule:#copyNot |
1836 bitBlitBytesFrom:1 to:4 withConstant:1 rule:#copyNot |
1837 |
1837 |
1838 #[1 2 3 4 5 6 7 8] |
1838 #[1 2 3 4 5 6 7 8] |
1839 bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+ |
1839 bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+ |
1840 " |
1840 " |
1841 ! |
1841 ! |
1842 |
1842 |
1843 bitOrBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart |
1843 bitOrBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart |
1844 "replace bytes in the receiver with the result of a bitOr operation. |
1844 "replace bytes in the receiver with the result of a bitOr operation. |
2154 } |
2154 } |
2155 src = srcNext; |
2155 src = srcNext; |
2156 } |
2156 } |
2157 RETURN ( self ); |
2157 RETURN ( self ); |
2158 } |
2158 } |
2159 console_printf("expandPixels: buffer size: self:%d expect at least:%d\n", |
2159 console_printf("expandPixels: buffer size: self:%"_ld_" expect at least:%"_ld_"\n", |
2160 __byteArraySize(self), srcBytes); |
2160 (INT)(__byteArraySize(self)), (INT)srcBytes); |
2161 console_printf("expandPixels: buffer size: arg:%d expect at least:%d\n", |
2161 console_printf("expandPixels: buffer size: arg:%"_ld_" expect at least:%"_ld_"\n", |
2162 __byteArraySize(aByteArray), dstBytes); |
2162 (INT)(__byteArraySize(aByteArray)), (INT)dstBytes); |
2163 } |
2163 } |
2164 console_printf("expandPixels: invalid args\n"); |
2164 console_printf("expandPixels: invalid args\n"); |
2165 |
2165 |
2166 fail: ; |
2166 fail: ; |
2167 %}. |
2167 %}. |
2218 REGISTER unsigned char *dst; |
2218 REGISTER unsigned char *dst; |
2219 REGISTER unsigned long *ldst; |
2219 REGISTER unsigned long *ldst; |
2220 REGISTER int cnt; |
2220 REGISTER int cnt; |
2221 |
2221 |
2222 if (__qClass(self) == @global(ByteArray)) { |
2222 if (__qClass(self) == @global(ByteArray)) { |
2223 cnt = __byteArraySize(self); |
2223 cnt = __byteArraySize(self); |
2224 dst = __ByteArrayInstPtr(self)->ba_element; |
2224 dst = __ByteArrayInstPtr(self)->ba_element; |
2225 if (((INT)dst & (sizeof(long)-1)) == 0) { // aligned |
2225 if (((INT)dst & (sizeof(long)-1)) == 0) { // aligned |
2226 ldst = (unsigned long *)dst; |
2226 ldst = (unsigned long *)dst; |
2227 while (cnt >= (sizeof(long))*4) { |
2227 while (cnt >= (sizeof(long))*4) { |
2228 ldst[0] = ~(ldst[0]); |
2228 ldst[0] = ~(ldst[0]); |
2229 ldst[1] = ~(ldst[1]); |
2229 ldst[1] = ~(ldst[1]); |
2230 ldst[2] = ~(ldst[2]); |
2230 ldst[2] = ~(ldst[2]); |
2231 ldst[3] = ~(ldst[3]); |
2231 ldst[3] = ~(ldst[3]); |
2232 ldst += 4; |
2232 ldst += 4; |
2233 cnt -= (sizeof(long))*4; |
2233 cnt -= (sizeof(long))*4; |
2234 } |
2234 } |
2235 while (cnt >= sizeof(long)) { |
2235 while (cnt >= sizeof(long)) { |
2236 *ldst = ~(*ldst); |
2236 *ldst = ~(*ldst); |
2237 ldst++; |
2237 ldst++; |
2238 cnt -= sizeof(long); |
2238 cnt -= sizeof(long); |
2239 } |
2239 } |
2240 dst = (unsigned char *)ldst; |
2240 dst = (unsigned char *)ldst; |
2241 } |
2241 } |
2242 while (cnt--) { |
2242 while (cnt--) { |
2243 *dst = ~(*dst); |
2243 *dst = ~(*dst); |
2244 dst++; |
2244 dst++; |
2245 } |
2245 } |
2246 RETURN ( self ); |
2246 RETURN ( self ); |
2247 } |
2247 } |
2248 %}. |
2248 %}. |
2249 self bitBlitBytesFrom:1 to:self size withConstant:16rFF rule:#bitXor: |
2249 self bitBlitBytesFrom:1 to:self size withConstant:16rFF rule:#bitXor: |
2250 |
2250 |
2251 " |
2251 " |
2252 #[1 2 3 4 5 6 7 8 9 10] copy invert |
2252 #[1 2 3 4 5 6 7 8 9 10] copy invert |
2253 #[1 2 3 4 5 6 7 8 9 10] copy |
2253 #[1 2 3 4 5 6 7 8 9 10] copy |
2254 bitBlitBytesFrom:1 to:10 withConstant:16rFF rule:#bitXor: |
2254 bitBlitBytesFrom:1 to:10 withConstant:16rFF rule:#bitXor: |
2255 |
2255 |
2256 |l| |
2256 |l| |
2257 l := ByteArray fromHexString:'0102030405060708090a0b0c0d0e0f1112131415161718191a1b1c1d1e1f'. |
2257 l := ByteArray fromHexString:'0102030405060708090a0b0c0d0e0f1112131415161718191a1b1c1d1e1f'. |
2258 Time millisecondsToRun:[ |
2258 Time millisecondsToRun:[ |
2259 1000000 timesRepeat:[ l invert ]. |
2259 1000000 timesRepeat:[ l invert ]. |
2260 ] |
2260 ] |
2261 " |
2261 " |
2262 ! |
2262 ! |
2263 |
2263 |
2264 reverse |
2264 reverse |
2265 "reverse the order of my elements inplace - |
2265 "reverse the order of my elements inplace - |
2416 " |
2416 " |
2417 ! |
2417 ! |
2418 |
2418 |
2419 swapBytes |
2419 swapBytes |
2420 "swap bytes inplace - |
2420 "swap bytes inplace - |
2421 Expects that the receiver has an even number of bytes; |
2421 Expects that the receiver has an even number of bytes; |
2422 if not, only the pairs excluding the last byte are swapped. |
2422 if not, only the pairs excluding the last byte are swapped. |
2423 written as a primitive for speed on image grabbing (if display order is different)." |
2423 written as a primitive for speed on image grabbing (if display order is different)." |
2424 |
2424 |
2425 %{ /* NOCONTEXT */ |
2425 %{ /* NOCONTEXT */ |
2426 |
2426 |
2427 REGISTER unsigned char *p; |
2427 REGISTER unsigned char *p; |
2428 REGISTER int cnt; |
2428 REGISTER int cnt; |
2429 REGISTER unsigned t; |
2429 REGISTER unsigned t; |
2430 |
2430 |
2431 if (__qClass(self) == @global(ByteArray)) { |
2431 if (__qClass(self) == @global(ByteArray)) { |
2432 cnt = __byteArraySize(self); |
2432 cnt = __byteArraySize(self); |
2433 cnt = cnt & ~1; /* make it even */ |
2433 cnt = cnt & ~1; /* make it even */ |
2434 p = __ByteArrayInstPtr(self)->ba_element; |
2434 p = __ByteArrayInstPtr(self)->ba_element; |
2435 |
2435 |
2436 while (cnt >= sizeof(INT)) { |
2436 while (cnt >= sizeof(INT)) { |
2437 unsigned INT i = ((unsigned INT *)p)[0]; |
2437 unsigned INT i = ((unsigned INT *)p)[0]; |
2438 |
2438 |
2439 #if __POINTER_SIZE__ == 8 |
2439 #if __POINTER_SIZE__ == 8 |
2440 i = ((i>>8) & 0x00FF00FF00FF00FF) | ((i & 0x00FF00FF00FF00FF) << 8); |
2440 i = ((i>>8) & 0x00FF00FF00FF00FF) | ((i & 0x00FF00FF00FF00FF) << 8); |
2441 #else |
2441 #else |
2442 i = ((i>>8) & 0x00FF00FF) | ((i & 0x00FF00FF) << 8); |
2442 i = ((i>>8) & 0x00FF00FF) | ((i & 0x00FF00FF) << 8); |
2443 #endif /* __POINTER_SIZE__ */ |
2443 #endif /* __POINTER_SIZE__ */ |
2444 ((unsigned INT *)p)[0] = i; |
2444 ((unsigned INT *)p)[0] = i; |
2445 p += sizeof(INT); |
2445 p += sizeof(INT); |
2446 cnt -= sizeof(INT); |
2446 cnt -= sizeof(INT); |
2447 } |
2447 } |
2448 while (cnt > 0) { |
2448 while (cnt > 0) { |
2449 unsigned short s; |
2449 unsigned short s; |
2450 |
2450 |
2451 s = ((unsigned short *)p)[0]; |
2451 s = ((unsigned short *)p)[0]; |
2452 s = (s >> 8) | (s << 8); |
2452 s = (s >> 8) | (s << 8); |
2453 ((unsigned short *)p)[0] = s; |
2453 ((unsigned short *)p)[0] = s; |
2454 p += 2; |
2454 p += 2; |
2455 cnt -= 2; |
2455 cnt -= 2; |
2456 } |
2456 } |
2457 RETURN ( self ); |
2457 RETURN ( self ); |
2458 } |
2458 } |
2459 %}. |
2459 %}. |
2460 ^ super swapBytes "/ rubbish - there is no one currenly |
2460 ^ super swapBytes "/ rubbish - there is no one currenly |
2461 |
2461 |
2462 " |
2462 " |
2463 #[1 2 3 4 5 6 7 8 9 10] copy swapBytes -> #[2 1 4 3 6 5 8 7 10 9] |
2463 #[1 2 3 4 5 6 7 8 9 10] copy swapBytes -> #[2 1 4 3 6 5 8 7 10 9] |
2464 #[1 2 3 4 5 6 7 8 9 10 11] copy swapBytes -> #[2 1 4 3 6 5 8 7 10 9 11] |
2464 #[1 2 3 4 5 6 7 8 9 10 11] copy swapBytes -> #[2 1 4 3 6 5 8 7 10 9 11] |
2465 #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18] copy swapBytes |
2465 #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18] copy swapBytes |
2466 " |
2466 " |
2467 ! |
2467 ! |
2468 |
2468 |
2469 swapIndex:i1 and:i2 |
2469 swapIndex:i1 and:i2 |
2470 "spap the bytes with i1 and i2" |
2470 "spap the bytes with i1 and i2" |
2475 unsigned int __i1, __i2; |
2475 unsigned int __i1, __i2; |
2476 int sz; |
2476 int sz; |
2477 unsigned int t; |
2477 unsigned int t; |
2478 |
2478 |
2479 if (__qClass(self) == @global(ByteArray) && __bothSmallInteger(i1, i2)) { |
2479 if (__qClass(self) == @global(ByteArray) && __bothSmallInteger(i1, i2)) { |
2480 __i1 = __intVal(i1) - 1; |
2480 __i1 = __intVal(i1) - 1; |
2481 __i2 = __intVal(i2) - 1; |
2481 __i2 = __intVal(i2) - 1; |
2482 sz = __byteArraySize(self); |
2482 sz = __byteArraySize(self); |
2483 p = __ByteArrayInstPtr(self)->ba_element; |
2483 p = __ByteArrayInstPtr(self)->ba_element; |
2484 if (__i1 < sz && __i2 < sz) { |
2484 if (__i1 < sz && __i2 < sz) { |
2485 t = p[__i1]; |
2485 t = p[__i1]; |
2486 p[__i1] = p[__i2]; |
2486 p[__i1] = p[__i2]; |
2487 p[__i2] = t; |
2487 p[__i2] = t; |
2488 } |
2488 } |
2489 RETURN ( self ); |
2489 RETURN ( self ); |
2490 } |
2490 } |
2491 %}. |
2491 %}. |
2492 ^ super swapIndex:i1 and:i2 "/ rubbish - there is no one currently |
2492 ^ super swapIndex:i1 and:i2 "/ rubbish - there is no one currently |
2493 |
2493 |
2494 " |
2494 " |
2596 "/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
2596 "/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
2597 |cls| |
2597 |cls| |
2598 |
2598 |
2599 cls := self class. |
2599 cls := self class. |
2600 ((cls == ByteArray or:[cls == ImmutableByteArray]) and:[aGCOrStream isStream]) ifTrue:[ |
2600 ((cls == ByteArray or:[cls == ImmutableByteArray]) and:[aGCOrStream isStream]) ifTrue:[ |
2601 self storeOn:aGCOrStream. |
2601 self storeOn:aGCOrStream. |
2602 ^ self |
2602 ^ self |
2603 ]. |
2603 ]. |
2604 ^ super displayOn:aGCOrStream |
2604 ^ super displayOn:aGCOrStream |
2605 |
2605 |
2606 "Created: 25.10.1995 / 13:33:26 / cg" |
2606 "Created: 25.10.1995 / 13:33:26 / cg" |
2607 "Modified: 22.4.1996 / 12:54:06 / cg" |
2607 "Modified: 22.4.1996 / 12:54:06 / cg" |
2800 %{ /* NOCONTEXT */ |
2800 %{ /* NOCONTEXT */ |
2801 REGISTER unsigned char *cp; |
2801 REGISTER unsigned char *cp; |
2802 REGISTER unsigned char *endP; |
2802 REGISTER unsigned char *endP; |
2803 |
2803 |
2804 if (__isByteArrayLike(self)) { |
2804 if (__isByteArrayLike(self)) { |
2805 cp = &(__ByteArrayInstPtr(self)->ba_element[0]); |
2805 cp = &(__ByteArrayInstPtr(self)->ba_element[0]); |
2806 endP = cp + __byteArraySize(self); |
2806 endP = cp + __byteArraySize(self); |
2807 #if __POINTER_SIZE__ == 8 |
2807 #if __POINTER_SIZE__ == 8 |
2808 while (cp+8 < endP) { |
2808 while (cp+8 < endP) { |
2809 if ( ((unsigned INT *)cp)[0] & 0x8080808080808080) RETURN( true ); |
2809 if ( ((unsigned INT *)cp)[0] & 0x8080808080808080) RETURN( true ); |
2810 cp += 8; |
2810 cp += 8; |
2811 } |
2811 } |
2812 #endif |
2812 #endif |
2813 while (cp+4 < endP) { |
2813 while (cp+4 < endP) { |
2814 if ( ((unsigned int *)cp)[0] & 0x80808080) RETURN( true ); |
2814 if ( ((unsigned int *)cp)[0] & 0x80808080) RETURN( true ); |
2815 cp += 4; |
2815 cp += 4; |
2816 } |
2816 } |
2817 while (cp < endP) { |
2817 while (cp < endP) { |
2818 if (*cp++ & 0x80) RETURN( true ); |
2818 if (*cp++ & 0x80) RETURN( true ); |
2819 } |
2819 } |
2820 RETURN ( false ); |
2820 RETURN ( false ); |
2821 } |
2821 } |
2822 %} |
2822 %} |
2823 . |
2823 . |
2824 ^ self contains:[:b | b bitTest:16r80]. |
2824 ^ self contains:[:b | b bitTest:16r80]. |
2825 |
2825 |
2839 REGISTER unsigned char *cp; |
2839 REGISTER unsigned char *cp; |
2840 REGISTER int index, max; |
2840 REGISTER int index, max; |
2841 int len; |
2841 int len; |
2842 |
2842 |
2843 if (__isByteArrayLike(self)) { |
2843 if (__isByteArrayLike(self)) { |
2844 max = 0; |
2844 max = 0; |
2845 index = 0; |
2845 index = 0; |
2846 len = __qSize(self) - OHDR_SIZE; |
2846 len = __qSize(self) - OHDR_SIZE; |
2847 cp = &(__ByteArrayInstPtr(self)->ba_element[0]); |
2847 cp = &(__ByteArrayInstPtr(self)->ba_element[0]); |
2848 |
2848 |
2849 while (++index <= len) { |
2849 while (++index <= len) { |
2850 unsigned int byte; |
2850 unsigned int byte; |
2851 |
2851 |
2852 byte = *cp; |
2852 byte = *cp; |
2853 cp++; |
2853 cp++; |
2854 if (byte > max) { |
2854 if (byte > max) { |
2855 max = byte; |
2855 max = byte; |
2856 if (byte == 255) break; |
2856 if (byte == 255) break; |
2857 } |
2857 } |
2858 } |
2858 } |
2859 RETURN ( __mkSmallInteger(max) ); |
2859 RETURN ( __mkSmallInteger(max) ); |
2860 } |
2860 } |
2861 %}. |
2861 %}. |
2862 ^ super max |
2862 ^ super max |
2863 |
2863 |
2864 " |
2864 " |
3008 REGISTER int byteValue; |
3008 REGISTER int byteValue; |
3009 REGISTER int len; |
3009 REGISTER int len; |
3010 OBJ cls; |
3010 OBJ cls; |
3011 |
3011 |
3012 if (__isSmallInteger(aByte) &&__isBytes(self)) { |
3012 if (__isSmallInteger(aByte) &&__isBytes(self)) { |
3013 byteValue = __intVal(aByte); |
3013 byteValue = __intVal(aByte); |
3014 |
3014 |
3015 if (byteValue & ~0xFF /* i.e. (byteValue < 0) || (byteValue > 255) */) { |
3015 if (byteValue & ~0xFF /* i.e. (byteValue < 0) || (byteValue > 255) */) { |
3016 /* |
3016 /* |
3017 * searching for something which cannot be found |
3017 * searching for something which cannot be found |
3018 */ |
3018 */ |
3019 RETURN ( __mkSmallInteger(0) ); |
3019 RETURN ( __mkSmallInteger(0) ); |
3020 } |
3020 } |
3021 |
3021 |
3022 if (__isSmallInteger(start)) { |
3022 if (__isSmallInteger(start)) { |
3023 index = __intVal(start); |
3023 index = __intVal(start); |
3024 len = __byteArraySize(self); |
3024 len = __byteArraySize(self); |
3025 cp = __ByteArrayInstPtr(self)->ba_element; |
3025 cp = __ByteArrayInstPtr(self)->ba_element; |
3026 if ((cls = __qClass(self)) != @global(ByteArray)) { |
3026 if ((cls = __qClass(self)) != @global(ByteArray)) { |
3027 int nInst; |
3027 int nInst; |
3028 |
3028 |
3029 nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3029 nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
3030 cp += nInst; |
3030 cp += nInst; |
3031 len -= nInst; |
3031 len -= nInst; |
3032 } |
3032 } |
3033 cp += index - 1; |
3033 cp += index - 1; |
3034 #ifdef __UNROLL_LOOPS__ |
3034 #ifdef __UNROLL_LOOPS__ |
3035 while ((index+4) < len) { |
3035 while ((index+4) < len) { |
3036 if (cp[0] == byteValue) { RETURN ( __mkSmallInteger(index) ); } |
3036 if (cp[0] == byteValue) { RETURN ( __mkSmallInteger(index) ); } |
3037 if (cp[1] == byteValue) { RETURN ( __mkSmallInteger(index+1) ); } |
3037 if (cp[1] == byteValue) { RETURN ( __mkSmallInteger(index+1) ); } |
3038 if (cp[2] == byteValue) { RETURN ( __mkSmallInteger(index+2) ); } |
3038 if (cp[2] == byteValue) { RETURN ( __mkSmallInteger(index+2) ); } |
3039 if (cp[3] == byteValue) { RETURN ( __mkSmallInteger(index+3) ); } |
3039 if (cp[3] == byteValue) { RETURN ( __mkSmallInteger(index+3) ); } |
3040 index += 4; |
3040 index += 4; |
3041 cp += 4; |
3041 cp += 4; |
3042 } |
3042 } |
3043 #endif |
3043 #endif |
3044 while (index <= len) { |
3044 while (index <= len) { |
3045 if (*cp == byteValue) { |
3045 if (*cp == byteValue) { |
3046 RETURN ( __mkSmallInteger(index) ); |
3046 RETURN ( __mkSmallInteger(index) ); |
3047 } |
3047 } |
3048 index++; |
3048 index++; |
3049 cp++; |
3049 cp++; |
3050 } |
3050 } |
3051 RETURN ( __mkSmallInteger(0) ); |
3051 RETURN ( __mkSmallInteger(0) ); |
3052 } |
3052 } |
3053 } |
3053 } |
3054 %}. |
3054 %}. |
3055 ^ super indexOf:aByte startingAt:start |
3055 ^ super indexOf:aByte startingAt:start |
3056 |
3056 |
3057 " |
3057 " |