[Pkg] The Trunk: Collections-ul.667.mcz

commits at source.squeak.org commits at source.squeak.org
Sat Oct 10 14:09:35 UTC 2015


Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.667.mcz

==================== Summary ====================

Name: Collections-ul.667
Author: ul
Time: 10 October 2015, 3:40:46.732 pm
UUID: 7cd785ff-1839-4075-ac56-4b71054529d8
Ancestors: Collections-topa.666

Added the missing methods of ByteArray's platform independent access category: #signedByteAt: #signedByteAt:put: #long64At:put:bigEndian: and #long64At:bigEndian:. The 64-bit methods are not optimized.

Added #associationClass to Dictionary and its subclasses, which returns the class of the associations the Dictionary holds. This allows us to simplify the implementations of #at:put: and friends in the subclasses.

String changes:
- introduced #asIntegerSigned: which converts the receiver to an Integer.
- #asSignedInteger should return nil for empty string.
- optimized #asUnsignedInteger as well

=============== Diff against Collections-topa.666 ===============

Item was added:
+ ----- Method: ByteArray>>long64At:bigEndian: (in category 'platform independent access') -----
+ long64At: index bigEndian: bigEndian
+ 	"Return a 64-bit signed integer quantity starting from the given byte index."
+ 
+ 	| value |
+ 	value := self unsignedLong64At: index bigEndian: bigEndian.
+ 	value digitLength < 8 ifTrue: [ ^value ].
+ 	(value digitAt: 8) < 16r80 ifTrue: [ ^value ].
+ 	^value - 16r10000000000000000!

Item was added:
+ ----- Method: ByteArray>>long64At:put:bigEndian: (in category 'platform independent access') -----
+ long64At: index put: value bigEndian: bigEndian
+ 	"Store a 64-bit signed integer quantity starting from the given byte index."
+ 	
+ 	^self
+ 		unsignedLong64At: index
+ 		put: (value negative
+ 			ifFalse: [ value ]
+ 			ifTrue: [ value + 16r10000000000000000 ])
+ 		bigEndian: bigEndian!

Item was added:
+ ----- Method: ByteArray>>signedByteAt: (in category 'platform independent access') -----
+ signedByteAt: index
+ 	"Return an 8-bit signed integer quantity from the given byte index."
+ 	
+ 	| byte |
+ 	(byte := self at: index) <= 16r7F ifTrue: [ ^byte ].
+ 	^byte - 16r100!

Item was added:
+ ----- Method: ByteArray>>signedByteAt:put: (in category 'platform independent access') -----
+ signedByteAt: index put: anInteger
+ 	"Store an 8-bit signed integer quantity at the given byte index."
+ 	
+ 	anInteger >= 0 ifTrue: [ ^self at: index put: anInteger ].
+ 	self at: index put: anInteger + 16r100.
+ 	^anInteger!

Item was added:
+ ----- Method: ByteString>>asIntegerSigned: (in category 'converting') -----
+ asIntegerSigned: signed
+ 	"Return the first decimal integer I can find or nil."
+ 
+ 	| index integerValue result size negative |
+ 	(size := self size) <= 16 ifFalse: [ ^super asIntegerSigned: signed ].
+ 	"Find the first character between $0 and $9."
+ 	index := 0.
+ 	[ (index := index + 1) <= size and: [ 
+ 		(integerValue := (self at: index) asInteger) <= 47 "$0 asInteger - 1" or: [ 
+ 			58 "$9 asInteger + 1" <= integerValue ] ] ] whileTrue.
+ 	index <= size ifFalse: [ ^nil ].
+ 	negative := signed and: [ 2 <= index and: [ (self at: index - 1) == $- ] ].
+ 	"Parse the number."
+ 	result := integerValue - 48 "$0 asInteger".
+ 	[ (index := index + 1) <= size
+ 		and: [ (integerValue := (self at: index) asInteger) <= 57 "$9 asInteger"
+ 		and: [ 48 "$0 asInteger" <= integerValue ] ] ]  whileTrue: [
+ 		result := result * 10 + integerValue - 48 ].
+ 	negative ifTrue: [ ^result negated ].
+ 	^result!

Item was added:
+ ----- Method: Dictionary>>associationClass (in category 'accessing') -----
+ associationClass
+ 
+ 	^Association!

Item was changed:
  ----- Method: Dictionary>>at:ifPresent:ifAbsentPut: (in category 'accessing') -----
  at: key ifPresent: oneArgBlock ifAbsentPut: absentBlock
  	"Lookup the given key in the receiver. If it is present, answer the value of
  	 evaluating oneArgBlock with the value associated with the key. Otherwise
  	 add the value of absentBlock under the key, and answer that value."
  
  	| index value |
  	index := self scanFor: key.
  	(array at: index) ifNotNil:
  		[:element|
  		 ^oneArgBlock value: element value].
  	value := absentBlock value.
+ 	self atNewIndex: index put: (self associationClass key: key value: value).
- 	self atNewIndex: index put: (Association key: key value: value).
  	^value!

Item was changed:
  ----- Method: Dictionary>>at:put: (in category 'accessing') -----
  at: key put: anObject 
  	"Set the value at key to be anObject.  If key is not found, create a
  	new entry for key and set is value to anObject. Answer anObject."
  
  	| index |
  	index := self scanFor: key.
  	(array at: index)
+ 		ifNil: [ self atNewIndex: index put: (self associationClass key: key value: anObject) ]
- 		ifNil: [ self atNewIndex: index put: (Association key: key value: anObject) ]
  		ifNotNil: [ :association | association value: anObject ].
  	^anObject!

Item was changed:
  ----- Method: Dictionary>>valueAtNewKey:put:atIndex:declareFrom: (in category 'private') -----
  valueAtNewKey: aKey put: anObject atIndex: index declareFrom: aDictionary 
  	"Support for coordinating class variable and global declarations
  	with variables that have been put in Undeclared so as to
  	redirect all references to the undeclared variable."
  
  	(aDictionary includesKey: aKey)
  		ifTrue: 
  			[self atNewIndex: index 
  				put: ((aDictionary associationAt: aKey) value: anObject).
  			aDictionary removeKey: aKey]
  		ifFalse: 
+ 			[self atNewIndex: index put: (self associationClass key: aKey value: anObject)]!
- 			[self atNewIndex: index put: (Association key: aKey value: anObject)]!

Item was changed:
  ----- Method: String>>asInteger (in category 'converting') -----
  asInteger 
+ 	
+ 	^self asIntegerSigned: true
- 	^self asSignedInteger
  !

Item was added:
+ ----- Method: String>>asIntegerSigned: (in category 'converting') -----
+ asIntegerSigned: signed
+ 	"Return the first decimal integer I can find or nil."
+ 
+ 	| index character size result negative |
+ 	index := 0.
+ 	size := self size.
+ 	"Find the first character between $0 and $9."
+ 	[ (index := index + 1) > size or: [ (self at: index) isDigit ] ] whileFalse.
+ 	index > size ifTrue: [ ^nil ].
+ 	negative := signed and: [ index > 1 and: [ (self at: index - 1) == $- ] ].
+ 	"Parse the number."
+ 	size - index > 15 ifTrue: [
+ 		negative ifTrue: [ index := index - 1 ].
+ 		^Integer readFrom: (
+ 			ReadStream
+ 				on: self
+ 				from: index
+ 				to: size) ].
+ 	result := (self at: index) digitValue.
+ 	[ (index := index + 1) <= size
+ 		and: [ (character := self at: index) isDigit ] ]  whileTrue: [
+ 		result := result * 10 + character digitValue ].
+ 	negative ifTrue: [ ^result negated ].
+ 	^result!

Item was changed:
  ----- Method: String>>asSignedInteger (in category 'converting') -----
  asSignedInteger
+ 	"Return the first signed integer I can find or nil."
+ 	
+ 	^self asIntegerSigned: true!
- 	"Returns the first signed integer it can find or nil."
- 
- 	| result character index negative |
- 	(self at: 1) isDigit
- 		ifTrue: [ index := 1 ]
- 		ifFalse: [ 
- 			index := self findFirst: [ :char | char isDigit ].
- 			index = 0 ifTrue: [ ^nil ] ].
- 	negative := index > 1 and: [ (self at: index - 1) == $- ].
- 	result := 0.
- 	[ index <= self size and: [ (character := self at: index) isDigit ] ] whileTrue: [
- 		result := result * 10 + character asciiValue - 48 "$0 asciiValue".
- 		index := index + 1 ].
- 	negative ifTrue: [ ^0 - result ].
- 	^result
- !

Item was changed:
  ----- Method: String>>asUnsignedInteger (in category 'converting') -----
  asUnsignedInteger 
+ 	"Returns the first unsigned integer I can find or nil."
- 	"Returns the first integer it can find or nil."
  
+ 	^self asIntegerSigned: false!
- 	| start stream |
- 	start := self findFirst: [:char | char isDigit].
- 	start isZero ifTrue: [^nil].
- 	stream := (ReadStream on: self) position: start - 1.
- 	^Integer readFrom: stream!

Item was added:
+ ----- Method: WeakKeyDictionary>>associationClass (in category 'accessing') -----
+ associationClass
+ 
+ 	^WeakKeyAssociation!

Item was changed:
  ----- Method: WeakKeyDictionary>>at:put: (in category 'accessing') -----
  at: key put: anObject 
  	"Set the value at key to be anObject.  If key is not found, create a new
  	entry for key and set is value to anObject. Answer anObject."
  	
- 	| index |
  	key ifNil: [ ^anObject ].
+ 	^super at: key put: anObject!
- 	index := self scanFor: key.
- 	(array at: index)
- 		ifNil: [ self atNewIndex: index put: (WeakKeyAssociation key: key value: anObject) ]
- 		ifNotNil: [ :association | association value: anObject ].
- 	^anObject!

Item was added:
+ ----- Method: WeakValueDictionary>>associationClass (in category 'accessing') -----
+ associationClass
+ 
+ 	^WeakValueAssociation!

Item was removed:
- ----- Method: WeakValueDictionary>>at:put: (in category 'accessing') -----
- at: key put: anObject 
- 	"Set the value at key to be anObject.  If key is not found, create a new
- 	entry for key and set is value to anObject. Answer anObject."
- 	| index element |
- 	index := self scanFor: key.
- 	element := array at: index.
- 	element == nil
- 		ifTrue: [self atNewIndex: index put: (WeakValueAssociation key: key value: anObject)]
- 		ifFalse: [element value: anObject].
- 	^ anObject!



More information about the Packages mailing list