Skip to content

Commit d0eecef

Browse files
committed
LZMA/FLZMA: fixed wrong value of numThreads/numTotalThreads - use system number of CPUs instead of -1 (default), if compressed from FM without dialog;
closes gh-353
1 parent 6c4f5fe commit d0eecef

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CPP/7zip/Compress/Lzma2Encoder.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "../Common/CWrappers.h"
1010
#include "../Common/StreamUtils.h"
11+
#include "../../Windows/System.h"
1112

1213
#include "Lzma2Encoder.h"
1314
#pragma warning(disable : 4127)
@@ -55,7 +56,10 @@ HRESULT SetLzma2Prop(PROPID propID, const PROPVARIANT &prop, CLzma2EncProps &lzm
5556
case NCoderPropID::kNumThreads:
5657
if (prop.vt != VT_UI4)
5758
return E_INVALIDARG;
58-
lzma2Props.numTotalThreads = (int)(prop.ulVal);
59+
lzma2Props.numTotalThreads = (
60+
((int)(prop.ulVal) > 0) ?
61+
(int)(prop.ulVal) : NWindows::NSystem::GetNumberOfProcessors()
62+
);
5963
break;
6064
default:
6165
RINOK(NLzma::SetLzmaProp(propID, prop, lzma2Props.lzmaProps))

CPP/7zip/Compress/LzmaEncoder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "../Common/CWrappers.h"
88
#include "../Common/StreamUtils.h"
9+
#include "../../Windows/System.h"
910

1011
#include "LzmaEncoder.h"
1112

@@ -158,7 +159,8 @@ HRESULT SetLzmaProp(PROPID propID, const PROPVARIANT &prop, CLzmaEncProps &ep)
158159
SET_PROP_32(kPosStateBits, pb)
159160
SET_PROP_32(kLitPosBits, lp)
160161
SET_PROP_32(kLitContextBits, lc)
161-
SET_PROP_32(kNumThreads, numThreads)
162+
case NCoderPropID::kNumThreads:
163+
ep.numThreads = (int)v > 0 ? (int)v : NWindows::NSystem::GetNumberOfProcessors(); break;
162164
default: return E_INVALIDARG;
163165
}
164166
return S_OK;

0 commit comments

Comments
 (0)