[squeak-dev] The Trunk: Compression-nice.12.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Dec 18 20:08:03 UTC 2009


Nicolas Cellier uploaded a new version of Compression to project The Trunk:
http://source.squeak.org/trunk/Compression-nice.12.mcz

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

Name: Compression-nice.12
Author: nice
Time: 18 December 2009, 9:07:50 am
UUID: b9ac9a27-ed19-4a28-9d18-0911f756a263
Ancestors: Compression-nice.11

Cosmetic changes from pharo
- temps local to block
- use ifNil:

=============== Diff against Compression-nice.11 ===============

Item was changed:
  ----- Method: Archive>>addTree:removingFirstCharacters:match: (in category 'archive operations') -----
  addTree: aFileNameOrDirectory removingFirstCharacters: n match: aBlock
+ 	| dir fullPath relativePath |
- 	| dir newMember fullPath relativePath |
  	dir := (aFileNameOrDirectory isString)
  		ifTrue: [ FileDirectory on: aFileNameOrDirectory ]
  		ifFalse: [ aFileNameOrDirectory ].
  	fullPath := dir pathName, dir slash.
  	relativePath := fullPath copyFrom: n + 1 to: fullPath size.
  	(dir entries select: [ :entry | aBlock value: entry])
+ 		do: [ :ea | | fullName newMember |
- 		do: [ :ea | | fullName |
  		fullName := fullPath, ea name.
  		newMember := ea isDirectory
  				ifTrue: [ self memberClass newFromDirectory: fullName ]
  				ifFalse: [ self memberClass newFromFile: fullName ].
  		newMember localFileName: relativePath, ea name.
  		self addMember: newMember.
  		ea isDirectory ifTrue: [ self addTree: fullName removingFirstCharacters: n match: aBlock].
  	].
  !

Item was changed:
  ----- Method: ZipEncoderNode>>encodeBitLength:from: (in category 'encoding') -----
  encodeBitLength: blCounts from: aTree
  	| index |
  	"Note: If bitLength is not nil then the tree must be broken"
+ 	bitLength ifNotNil: [self error:'Huffman tree is broken'].
+ 	parent  
+ 		ifNil: [bitLength := 0]
+ 		ifNotNil: [bitLength := parent bitLength + 1].
- 	bitLength == nil ifFalse:[self error:'Huffman tree is broken'].
- 	parent = nil 
- 		ifTrue:[bitLength := 0]
- 		ifFalse:[bitLength := parent bitLength + 1].
  	self isLeaf ifTrue:[
  		index := bitLength + 1.
  		blCounts at: index put: (blCounts at: index) + 1.
  	] ifFalse:[
  		left encodeBitLength: blCounts from: aTree.
  		right encodeBitLength: blCounts from: aTree.
  	].!

Item was changed:
  ----- Method: ZipWriteStream>>flushBlock: (in category 'encoding') -----
  flushBlock: lastBlock
  	"Send the current block"
  	| lastFlag bitsRequired method bitsSent
  	storedLength fixedLength dynamicLength 
  	blTree lTree dTree blBits blFreq |
  
  	lastFlag := lastBlock ifTrue:[1] ifFalse:[0].
  
  	"Compute the literal/length and distance tree"
  	lTree := ZipEncoderTree buildTreeFrom: literalFreq maxDepth: MaxBits.
  	dTree := ZipEncoderTree buildTreeFrom: distanceFreq maxDepth: MaxBits.
  
  	"Compute the bit length tree"
  	blBits := lTree bitLengths, dTree bitLengths.
  	blFreq := WordArray new: MaxBitLengthCodes.
  	self scanBitLengths: blBits into: blFreq.
  	blTree := ZipEncoderTree buildTreeFrom: blFreq maxDepth: MaxBitLengthBits.
  
  	"Compute the bit length for the current block.
  	Note: Most of this could be computed on the fly but it's getting
  	really ugly in this case so we do it afterwards."
  	storedLength := self storedBlockSize.
  	fixedLength := self fixedBlockSizeFor: lTree and: dTree.
  	dynamicLength := self dynamicBlockSizeFor: lTree and: dTree 
  							using: blTree and: blFreq.
  	VerboseLevel > 1 ifTrue:[
  		Transcript cr; show:'Block sizes (S/F/D):';
  			space; print: storedLength // 8; 
  			nextPut:$/; print: fixedLength // 8; 
  			nextPut:$/; print: dynamicLength // 8; space; endEntry].
  
  	"Check which method to use"
  	method := self forcedMethod.
+ 	method ifNil:[
- 	method == nil ifTrue:[
  		method := (storedLength < fixedLength and:[storedLength < dynamicLength]) 
  			ifTrue:[#stored]
  			ifFalse:[fixedLength < dynamicLength ifTrue:[#fixed] ifFalse:[#dynamic]]].
  	(method == #stored and:[blockStart < 0]) ifTrue:[
  		"Cannot use #stored if the block is not available"
  		method := fixedLength < dynamicLength ifTrue:[#fixed] ifFalse:[#dynamic]].
  
  	bitsSent := encoder bitPosition. "# of bits sent before this block"
  	bitsRequired := nil.
  
  	(method == #stored) ifTrue:[
  		VerboseLevel > 0 ifTrue:[Transcript show:'S'].
  		bitsRequired := storedLength.
  		encoder nextBits: 3 put: StoredBlock << 1 + lastFlag.
  		self sendStoredBlock].
  
  	(method == #fixed) ifTrue:[
  		VerboseLevel > 0 ifTrue:[Transcript show:'F'].
  		bitsRequired := fixedLength.
  		encoder nextBits: 3 put: FixedBlock << 1 + lastFlag.
  		self sendFixedBlock].
  
  	(method == #dynamic) ifTrue:[
  		VerboseLevel > 0 ifTrue:[Transcript show:'D'].
  		bitsRequired := dynamicLength.
  		encoder nextBits: 3 put: DynamicBlock << 1 + lastFlag.
  		self sendDynamicBlock: blTree 
  			literalTree: lTree 
  			distanceTree: dTree 
  			bitLengths: blBits].
  
  	bitsRequired = (encoder bitPosition - bitsSent)
  		ifFalse:[self error:'Bits size mismatch'].
  
  	lastBlock 
  		ifTrue:[self release]
  		ifFalse:[self initializeNewBlock].!




More information about the Squeak-dev mailing list