Nicolas Cellier uploaded a new version of Collections to project The Trunk: http://source.squeak.org/trunk/Collections-nice.1060.mcz
==================== Summary ====================
Name: Collections-nice.1060 Author: nice Time: 27 February 2024, 11:08:13.826491 pm UUID: 335742d4-2ba3-4c02-8019-86ff466a5772 Ancestors: Collections-cmm.1059, Collections-nice.1059
Merge Collections-cmm.1059, Collections-nice.1059
=============== Diff against Collections-cmm.1059 ===============
Item was added: + ----- Method: RawBitsArray>>byteAt: (in category 'accessing') ----- + byteAt: anIndex + "Access a byte of the receiver, considered as a raw sequence of bytes. + This is a memory efficient implementation of: + ((self copy changeClassTo: ByteArray) at: anIndex)" + | int mask stride index shift | + self class isBytes + ifTrue: [^ self basicAt: anIndex]. + mask := 16rFF. + stride := self bytesPerBasicElement. + index := anIndex - 1 // stride + 1. + shift := anIndex - 1 \ stride * -8. + Smalltalk isLittleEndian ifFalse: [shift := stride - 1 * 8 - shift]. + int := self basicAt: index. + int := int bitShift: shift. + int := int bitAnd: mask. + ^int!
Item was added: + ----- Method: RawBitsArray>>byteAt:put: (in category 'accessing') ----- + byteAt: anIndex put: aByte + "Modify a byte of the receiver, considered as a raw sequence of bytes. + This is a less scary implementation than: + ([:class | ((self changeClassTo: ByteArray) at: anIndex put: aByte) changeClassTo: class] value: self class)" + | int stride index shift mask | + self class isBytes + ifTrue: [^ self basicAt: anIndex put: aByte]. + mask := 16rFF. + stride := self bytesPerBasicElement. + index := anIndex - 1 // stride + 1. + shift := anIndex - 1 \ stride * 8. + Smalltalk isLittleEndian ifFalse: [shift := stride - 1 * 8 - shift]. + int := self basicAt: index. + int := int bitClear: (mask bitShift: shift). + int := int bitOr: (aByte bitShift: shift). + self basicAt: index put: int. + ^aByte!
Item was added: + ----- Method: RawBitsArray>>reverseEndianness (in category 'converting') ----- + reverseEndianness + "reverse the endianness for each element" + + self class isBytes ifTrue: [^self]. + self class isWords ifTrue: [^self swapWords]. + self class isLongs ifTrue: [^self swapDoubleWords]. + self class isShorts ifTrue: [^self swapDoubleBytes]. + self error: 'this is not a collection of 1,2,4 or 8 bytes elements'!
Item was added: + ----- Method: RawBitsArray>>swap16pairs (in category 'private') ----- + swap16pairs + "Swap every pair of double-bytes + Example: #[ 1 2 3 4 5 6 7 8 ] copy swap16pairs => #[ 3 4 1 2 7 8 5 6] + Implementation notes: this is the same as swapHalves, except that swapHalves only work for WordArray" + + | hack blt | + "The implementation is a hack, but fast for large ranges" + hack := Form new hackBits: self. + blt := (BitBlt toForm: hack) sourceForm: hack. + blt combinationRule: Form reverse. "XOR" + blt sourceY: 0; destY: 0; height: self byteSize//4; width: 2. + blt sourceX: 0; destX: 2; copyBits. "Exchange double-bytes 0 and 1" + blt sourceX: 2; destX: 0; copyBits. + blt sourceX: 0; destX: 2; copyBits.!
Item was added: + ----- Method: RawBitsArray>>swap32pairs (in category 'private') ----- + swap32pairs + "Swap every pair of words + Example: #[ 1 2 3 4 5 6 7 8 ] copy swap32pairs => #[ 5 6 7 8 1 2 3 4 ]" + + | hack blt | + "The implementation is a hack, but fast for large ranges" + hack := Form new hackBits: self width: 8. + blt := (BitBlt toForm: hack) sourceForm: hack. + blt combinationRule: Form reverse. "XOR" + blt sourceY: 0; destY: 0; height: self byteSize//8; width: 4. + blt sourceX: 0; destX: 4; copyBits. "Exchange words 0 and 1" + blt sourceX: 4; destX: 0; copyBits. + blt sourceX: 0; destX: 4; copyBits.!
Item was added: + ----- Method: RawBitsArray>>swap8pairs (in category 'private') ----- + swap8pairs + "Swap every pair of bytes + Example: #[ 1 2 3 4 5 6 ] copy swap8pairs => #[ 2 1 4 3 6 5 ]" + + | hack blt | + "The implementation is a hack, but fast for large ranges" + hack := Form new hackBits: self. + blt := (BitBlt toForm: hack) sourceForm: hack. + blt combinationRule: Form reverse. "XOR" + blt sourceY: 0; destY: 0; height: self byteSize//4; width: 1. + blt sourceX: 0; destX: 1; copyBits. "Exchange bytes 0 and 1" + blt sourceX: 1; destX: 0; copyBits. + blt sourceX: 0; destX: 1; copyBits. + blt sourceX: 2; destX: 3; copyBits. "Exchange bytes 2 and 3" + blt sourceX: 3; destX: 2; copyBits. + blt sourceX: 2; destX: 3; copyBits. + self byteSize\4 >= 2 + ifTrue: + ["The lines in a From must fit on a Word boundary. + Handle the excess bytes" + | n tmp | + n := self byteSize // 4 * 4. + tmp := self byteAt: n + 1. + self byteAt: n + 1 put: (self byteAt: n + 2). + self byteAt: n + 2 put: tmp.]!
Item was added: + ----- Method: RawBitsArray>>swapDoubleBytes (in category 'private') ----- + swapDoubleBytes + "Perform a bigEndian/littleEndian byte reversal of my double bytes. + Assume that our byte size is a multiple of souble byte size (2) + If it's not the case, trailing bytes would be left unchanged" + + self swap8pairs!
Item was added: + ----- Method: RawBitsArray>>swapDoubleWords (in category 'private') ----- + swapDoubleWords + "Perform a bigEndian/littleEndian byte reversal of my double words. + Assume that our byte size is a multiple of double word size (8) + If it's not the case, 4 trailing bytes might be altered" + + self swap32pairs. "#[1 2 3 4 5 6 7 8] copy swap32pairs => #[5 6 7 8 1 2 3 4]" + self swapWords "#[5 6 7 8 1 2 3 4] copy swapWords => #[8 7 6 5 4 3 2 1]"!
Item was added: + ----- Method: RawBitsArray>>swapWords (in category 'private') ----- + swapWords + "Perform a bigEndian/littleEndian byte reversal of my words. + Assume that our byte size is a multiple of word size (4) + If it's not the case, trailing bytes will remain unchanged" + + | hack blt | + "The implementation is a hack, but fast for large ranges" + hack := Form new hackBits: self. + blt := (BitBlt toForm: hack) sourceForm: hack. + blt combinationRule: Form reverse. "XOR" + blt sourceY: 0; destY: 0; height: self byteSize//4; width: 1. + blt sourceX: 0; destX: 3; copyBits. "Exchange bytes 0 and 3" + blt sourceX: 3; destX: 0; copyBits. + blt sourceX: 0; destX: 3; copyBits. + blt sourceX: 2; destX: 1; copyBits. "Exchange bytes 1 and 2" + blt sourceX: 1; destX: 2; copyBits. + blt sourceX: 2; destX: 1; copyBits.!
packages@lists.squeakfoundation.org