" Smalltalk/ByteArray.st -*- Smalltalk -*- " ByteArray : ArrayedCollection () Object isByteArray [ ^false ] ByteArray isByteArray [ ^true ] ByteArray new: newSize [ | array | array := self _clone. { if (_isIntegerObject(v_newSize)) { struct t_Array *array= (struct t_Array *)v_array; array->size= v_newSize; array->_elements= (oop)_newBytes(_integerValue(v_newSize)); return v_array; } }. ^self primitiveFailed ] ByteArray byteAt: index [ { struct t_Array *this= (struct t_Array *)self; if (_isIntegerObject(v_index) && ((unsigned)v_index < (unsigned)this->size)) return _integerObject(((unsigned char *)this->_elements)[_integerValue(v_index)]); }. ^index isInteger ifTrue: [self errorSubscriptBounds: index] ifFalse: [self errorNonIntegerIndex: index]. ] ByteArray at: index [ ^self byteAt: index ] ByteArray byteAt: index put: anObject [ { struct t_Array *this= (struct t_Array *)self; if (_isIntegerObject(v_index) && ((unsigned)v_index < (unsigned)this->size) && _isIntegerObject(v_anObject) && ((unsigned)v_anObject < (unsigned)_integerObject(256))) { ((unsigned char *)this->_elements)[_integerValue(v_index)]= _integerValue(v_anObject); return v_anObject; } }. ^(anObject isInteger and: [anObject >= 0 and: [anObject <= 255]]) ifTrue: [ index isInteger ifTrue: [ self errorSubscriptBounds: index ] ifFalse: [ self errorNonIntegerIndex: index ] ] ifFalse: [ self errorImproperStore: anObject ] ] ByteArray at: index put: anObject [ ^self byteAt: index put: anObject ] ByteArray replaceFrom: start to: stop with: replacement startingAt: repStart [ " Destructively replace elements from start to stop in the receiver starting at index, repStart, in the sequenceable collection, replacementCollection. Answer the receiver. " | length repEnd | length := stop - start. repEnd := repStart + length. (replacement isByteArray and: [start >= 0 and: [length >= 0 and: [stop <= self size and: [repEnd <= replacement size]]]]) ifTrue: [{ memmove(((char *)((struct t_ByteArray *)self)->_elements) + _integerValue(v_start), ((char *)((struct t_ByteArray *)v_replacement)->_elements) + _integerValue(v_repStart), _integerValue(v_length)) }] ifFalse: [super replaceFrom: start to: stop with: replacement startingAt: repStart] ] ByteArray printOn: aStream [ self printNameOn: aStream. aStream nextPutAll: '#['. self do: [:element | aStream print: element; space]. self isEmpty ifFalse: [aStream skip: -1]. aStream nextPut: $] ] " ByteArray print [ | first | first := true. '#[' print. self do: [ :element | first ifTrue: [ first := false ] ifFalse: [ ' ' print ]. element print ]. ']' print. ] " ImmutableByteArray : ByteArray () ImmutableByteArray byteAt: index put: anObject [ ^self errorCannotModify ] ImmutableByteArray at: index put: anObject [ ^self errorCannotModify ] ImmutableByteArray species [ ^ByteArray ]