From 4e6d3beea990438eb4dee4f585ece5499d3f3cda Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Tue, 28 Aug 2018 11:21:33 +0300 Subject: [PATCH] [LZMA] Replace LZMAProperties.updateProperties with init from lzma byte and dict size --- Sources/7-Zip/7zFolder.swift | 3 +-- Sources/LZMA/LZMAProperties.swift | 9 +++------ Sources/LZMA2/LZMA2Decoder.swift | 3 ++- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Sources/7-Zip/7zFolder.swift b/Sources/7-Zip/7zFolder.swift index 14b7f181..b695fe21 100644 --- a/Sources/7-Zip/7zFolder.swift +++ b/Sources/7-Zip/7zFolder.swift @@ -171,12 +171,11 @@ class SevenZipFolder { properties.count == 5 else { throw LZMAError.wrongProperties } - var lzmaProperties = try LZMAProperties(lzmaByte: properties[0]) var dictionarySize = 0 for i in 1..<4 { dictionarySize |= properties[i].toInt() << (8 * (i - 1)) } - lzmaProperties.dictionarySize = dictionarySize + let lzmaProperties = try LZMAProperties(lzmaByte: properties[0], dictionarySize) decodedData = try LZMA.decompress(data: decodedData, properties: lzmaProperties, uncompressedSize: unpackSize) diff --git a/Sources/LZMA/LZMAProperties.swift b/Sources/LZMA/LZMAProperties.swift index 3ea9c8c4..524cda19 100644 --- a/Sources/LZMA/LZMAProperties.swift +++ b/Sources/LZMA/LZMAProperties.swift @@ -30,12 +30,7 @@ public struct LZMAProperties { self.dictionarySize = 0 } - init(lzmaByte: UInt8) throws { - self.init() - try self.updateProperties(lzmaByte: lzmaByte) - } - - mutating func updateProperties(lzmaByte: UInt8) throws { + init(lzmaByte: UInt8, _ dictSize: Int) throws { guard lzmaByte < 9 * 5 * 5 else { throw LZMAError.wrongProperties } @@ -44,6 +39,8 @@ public struct LZMAProperties { self.lc = intByte % 9 self.pb = (intByte / 9) / 5 self.lp = (intByte / 9) % 5 + + self.dictionarySize = dictSize } } diff --git a/Sources/LZMA2/LZMA2Decoder.swift b/Sources/LZMA2/LZMA2Decoder.swift index 1c134635..646c0e71 100644 --- a/Sources/LZMA2/LZMA2Decoder.swift +++ b/Sources/LZMA2/LZMA2Decoder.swift @@ -99,7 +99,8 @@ final class LZMA2Decoder { scheme and resets decoder's state and sub-decoders. */ private func updateProperties() throws { - try self.decoder.properties.updateProperties(lzmaByte: byteReader.byte()) + self.decoder.properties = try LZMAProperties(lzmaByte: byteReader.byte(), + self.decoder.properties.dictionarySize) self.decoder.resetStateAndDecoders() }