mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
Moved initial values for properties of lzma classes to their declarations (where possible).
This commit is contained in:
@@ -18,8 +18,8 @@ final class LZMABitTreeDecoder {
|
||||
|
||||
init(numBits: Int, _ pointerData: inout DataWithPointer) {
|
||||
self.pointerData = pointerData
|
||||
|
||||
self.probs = Array(repeating: LZMADecoder.Constants.probInitValue, count: 1 << numBits)
|
||||
self.probs = Array(repeating: LZMADecoder.Constants.probInitValue,
|
||||
count: 1 << numBits)
|
||||
self.numBits = numBits
|
||||
}
|
||||
|
||||
@@ -35,8 +35,10 @@ final class LZMABitTreeDecoder {
|
||||
|
||||
func reverseDecode(with rangeDecoder: inout LZMARangeDecoder) -> Int {
|
||||
lzmaDiagPrint("!!!BitTreeReverseDecode")
|
||||
return LZMABitTreeDecoder.bitTreeReverseDecode(probs: &self.probs, startIndex: 0, bits: self.numBits,
|
||||
rangeDecoder: &rangeDecoder)
|
||||
return LZMABitTreeDecoder.bitTreeReverseDecode(probs: &self.probs,
|
||||
startIndex: 0,
|
||||
bits: self.numBits,
|
||||
rangeDecoder: &rangeDecoder)
|
||||
}
|
||||
|
||||
static func bitTreeReverseDecode(probs: inout [Int], startIndex: Int, bits: Int,
|
||||
|
||||
+22
-33
@@ -39,7 +39,7 @@ final class LZMADecoder {
|
||||
|
||||
private var outWindow: LZMAOutWindow
|
||||
private var rangeDecoder: LZMARangeDecoder
|
||||
private var posSlotDecoder: [LZMABitTreeDecoder]
|
||||
private var posSlotDecoder: [LZMABitTreeDecoder] = []
|
||||
private var alignDecoder: LZMABitTreeDecoder
|
||||
private var lenDecoder: LZMALenDecoder
|
||||
private var repLenDecoder: LZMALenDecoder
|
||||
@@ -49,23 +49,30 @@ final class LZMADecoder {
|
||||
Each table contains 0x300 probabilities.
|
||||
*/
|
||||
private var literalProbs: [[Int]]
|
||||
private var isMatch: [Int]
|
||||
private var isRep: [Int]
|
||||
private var isRepG0: [Int]
|
||||
private var isRepG1: [Int]
|
||||
private var isRepG2: [Int]
|
||||
private var isRep0Long: [Int]
|
||||
// These arrays are used to select type of match or literal.
|
||||
private var isMatch: [Int] = Array(repeating: Constants.probInitValue,
|
||||
count: Constants.numStates << Constants.numPosBitsMax)
|
||||
private var isRep: [Int] = Array(repeating: Constants.probInitValue,
|
||||
count: Constants.numStates)
|
||||
private var isRepG0: [Int] = Array(repeating: Constants.probInitValue,
|
||||
count: Constants.numStates)
|
||||
private var isRepG1: [Int] = Array(repeating: Constants.probInitValue,
|
||||
count: Constants.numStates)
|
||||
private var isRepG2: [Int] = Array(repeating: Constants.probInitValue,
|
||||
count: Constants.numStates)
|
||||
private var isRep0Long: [Int] = Array(repeating: Constants.probInitValue,
|
||||
count: Constants.numStates << Constants.numPosBitsMax)
|
||||
|
||||
private var posDecoders: [Int]
|
||||
|
||||
// 'Distance history table'.
|
||||
private var rep0: Int
|
||||
private var rep1: Int
|
||||
private var rep2: Int
|
||||
private var rep3: Int
|
||||
private var rep0: Int = 0
|
||||
private var rep1: Int = 0
|
||||
private var rep2: Int = 0
|
||||
private var rep3: Int = 0
|
||||
|
||||
/// Is used to select exact variable from 'IsRep', 'IsRepG0', 'IsRepG1æ and 'IsRepG2' arrays.
|
||||
private var state: Int
|
||||
private var state: Int = 0
|
||||
|
||||
init(lc: UInt8, lp: UInt8, pb: UInt8, dictionarySize: Int, uncompressedSize: inout Int,
|
||||
_ pointerData: inout DataWithPointer) throws {
|
||||
@@ -88,19 +95,10 @@ final class LZMADecoder {
|
||||
}
|
||||
self.rangeDecoder = rD
|
||||
|
||||
self.literalProbs = Array(repeating: Array(repeating: Constants.probInitValue, count: 0x300),
|
||||
count: 1 << (lc + lp).toInt())
|
||||
// These arrays are used to select type of match or literal.
|
||||
self.isMatch = Array(repeating: Constants.probInitValue,
|
||||
count: Constants.numStates << Constants.numPosBitsMax)
|
||||
self.isRep = Array(repeating: Constants.probInitValue, count: Constants.numStates)
|
||||
self.isRepG0 = Array(repeating: Constants.probInitValue, count: Constants.numStates)
|
||||
self.isRepG1 = Array(repeating: Constants.probInitValue, count: Constants.numStates)
|
||||
self.isRepG2 = Array(repeating: Constants.probInitValue, count: Constants.numStates)
|
||||
self.isRep0Long = Array(repeating: Constants.probInitValue,
|
||||
count: Constants.numStates << Constants.numPosBitsMax)
|
||||
self.literalProbs = Array(repeating: Array(repeating: Constants.probInitValue,
|
||||
count: 0x300),
|
||||
count: 1 << (lc + lp).toInt())
|
||||
|
||||
self.posSlotDecoder = []
|
||||
for _ in 0..<Constants.numLenToPosStates {
|
||||
self.posSlotDecoder.append(LZMABitTreeDecoder(numBits: 6, &self.pointerData))
|
||||
}
|
||||
@@ -111,15 +109,6 @@ final class LZMADecoder {
|
||||
// There are two types of matches so we need two decoders for them.
|
||||
self.lenDecoder = LZMALenDecoder(&self.pointerData)
|
||||
self.repLenDecoder = LZMALenDecoder(&self.pointerData)
|
||||
|
||||
self.rep0 = 0
|
||||
self.rep1 = 0
|
||||
self.rep2 = 0
|
||||
self.rep3 = 0
|
||||
|
||||
self.state = 0
|
||||
|
||||
|
||||
}
|
||||
|
||||
func decodeLZMA() throws -> [UInt8] {
|
||||
|
||||
@@ -12,20 +12,16 @@ final class LZMALenDecoder {
|
||||
|
||||
private var pointerData: DataWithPointer
|
||||
|
||||
private var choice: Int
|
||||
private var choice2: Int
|
||||
private var lowCoder: [LZMABitTreeDecoder]
|
||||
private var midCoder: [LZMABitTreeDecoder]
|
||||
private var choice: Int = LZMADecoder.Constants.probInitValue
|
||||
private var choice2: Int = LZMADecoder.Constants.probInitValue
|
||||
private var lowCoder: [LZMABitTreeDecoder] = []
|
||||
private var midCoder: [LZMABitTreeDecoder] = []
|
||||
private var highCoder: LZMABitTreeDecoder
|
||||
|
||||
init(_ pointerData: inout DataWithPointer) {
|
||||
self.pointerData = pointerData
|
||||
|
||||
self.choice = LZMADecoder.Constants.probInitValue
|
||||
self.choice2 = LZMADecoder.Constants.probInitValue
|
||||
self.highCoder = LZMABitTreeDecoder(numBits: 8, &self.pointerData)
|
||||
self.lowCoder = []
|
||||
self.midCoder = []
|
||||
for _ in 0..<(1 << LZMADecoder.Constants.numPosBitsMax) {
|
||||
self.lowCoder.append(LZMABitTreeDecoder(numBits: 3, &self.pointerData))
|
||||
self.midCoder.append(LZMABitTreeDecoder(numBits: 3, &self.pointerData))
|
||||
|
||||
@@ -11,11 +11,11 @@ import Foundation
|
||||
final class LZMAOutWindow {
|
||||
|
||||
private var byteBuffer: [UInt8]
|
||||
private var position: Int
|
||||
private var position: Int = 0
|
||||
private var size: Int
|
||||
private var isFull: Bool
|
||||
private var isFull: Bool = false
|
||||
|
||||
private(set) var totalPosition: Int
|
||||
private(set) var totalPosition: Int = 0
|
||||
|
||||
var isEmpty: Bool {
|
||||
return self.position == 0 && !self.isFull
|
||||
@@ -23,15 +23,11 @@ final class LZMAOutWindow {
|
||||
|
||||
init(dictSize: Int) {
|
||||
self.byteBuffer = Array(repeating: 0, count: dictSize)
|
||||
self.position = 0
|
||||
self.totalPosition = 0
|
||||
self.size = dictSize
|
||||
self.isFull = false
|
||||
}
|
||||
|
||||
func put(_
|
||||
byte: UInt8, _ out: inout [UInt8], _ outIndex: inout Int,
|
||||
_ uncompressedSize: inout Int) {
|
||||
func put(_ byte: UInt8, _ out: inout [UInt8], _ outIndex: inout Int,
|
||||
_ uncompressedSize: inout Int) {
|
||||
self.totalPosition += 1
|
||||
self.byteBuffer[position] = byte
|
||||
self.position += 1
|
||||
|
||||
@@ -12,9 +12,9 @@ final class LZMARangeDecoder {
|
||||
|
||||
private var pointerData: DataWithPointer
|
||||
|
||||
private var range: UInt32
|
||||
private var code: UInt32
|
||||
private(set) var isCorrupted: Bool
|
||||
private var range: UInt32 = 0xFFFFFFFF
|
||||
private var code: UInt32 = 0
|
||||
private(set) var isCorrupted: Bool = false
|
||||
|
||||
var isFinishedOK: Bool {
|
||||
return self.code == 0
|
||||
@@ -22,11 +22,7 @@ final class LZMARangeDecoder {
|
||||
|
||||
init?(_ pointerData: inout DataWithPointer) {
|
||||
self.pointerData = pointerData
|
||||
|
||||
self.isCorrupted = false
|
||||
self.range = 0xFFFFFFFF
|
||||
self.code = 0
|
||||
|
||||
|
||||
let byte = self.pointerData.alignedByte()
|
||||
for _ in 0..<4 {
|
||||
self.code = (self.code << 8) | UInt32(self.pointerData.alignedByte())
|
||||
|
||||
Reference in New Issue
Block a user