Skip to content

Commit 12ff6d7

Browse files
committed
Partial reverse of commit 2bc7edf due to perf regression. Reintroduce the one file branch
1 parent 90a80aa commit 12ff6d7

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

src/app/BlockCompressor.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,45 @@ int BlockCompressor::compress(uint64& outputSize)
314314
_ctx.putInt("verbosity", _verbosity);
315315

316316
// Run the task(s)
317-
{
317+
if (nbFiles == 1) {
318+
string oName = formattedOutName;
319+
string iName = "STDIN";
320+
321+
if (isStdIn == true) {
322+
if (oName.length() == 0) {
323+
oName = "STDOUT";
324+
}
325+
} else {
326+
iName = files[0].fullPath();
327+
_ctx.putLong("fileSize", files[0]._size);
328+
329+
// Set the block size to optimize compression ratio when possible
330+
if ((_autoBlockSize == true) && (_jobs > 0)) {
331+
const int64 bl = files[0]._size / _jobs;
332+
_blockSize = int(max(min((bl + 63) & ~63, int64(MAX_BLOCK_SIZE)), int64(MIN_BLOCK_SIZE)));
333+
}
334+
335+
if (oName.length() == 0) {
336+
oName = iName + ".knz";
337+
}
338+
else if ((inputIsDir == true) && (specialOutput == false)) {
339+
oName = formattedOutName + iName.substr(formattedInName.size()) + ".knz";
340+
}
341+
}
342+
343+
_ctx.putString("inputName", iName);
344+
_ctx.putString("outputName", oName);
345+
FileCompressTask<FileCompressResult> task(_ctx, _listeners);
346+
FileCompressResult fcr = task.run();
347+
res = fcr._code;
348+
read = fcr._read;
349+
written = fcr._written;
350+
351+
if (res != 0) {
352+
cerr << fcr._errMsg << endl;
353+
}
354+
}
355+
else {
318356
vector<FileCompressTask<FileCompressResult>*> tasks;
319357
vector<int> jobsPerTask(nbFiles);
320358
Global::computeJobsPerTask(jobsPerTask.data(), _jobs, nbFiles);

src/app/BlockDecompressor.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,49 @@ int BlockDecompressor::decompress(uint64& inputSize)
204204
_ctx.putInt("verbosity", _verbosity);
205205

206206
// Run the task(s)
207-
{
207+
if (nbFiles == 1) {
208+
string oName = formattedOutName;
209+
string iName = "STDIN";
210+
211+
if (isStdIn == true) {
212+
if (oName.length() == 0) {
213+
oName = "STDOUT";
214+
}
215+
}
216+
else {
217+
iName = files[0].fullPath();
218+
_ctx.putLong("fileSize", files[0]._size);
219+
220+
if (oName.length() == 0) {
221+
oName = iName;
222+
223+
if ((upperInputName.length() >= 4) && (upperInputName.substr(upperInputName.length() - 4) == ".KNZ"))
224+
oName.resize(oName.length() - 4);
225+
else
226+
oName = oName + ".bak";
227+
}
228+
else if ((inputIsDir == true) && (specialOutput == false)) {
229+
oName = formattedOutName + iName.substr(formattedInName.size());
230+
231+
if ((upperInputName.length() >= 4) && (upperInputName.substr(upperInputName.length() - 4) == ".KNZ"))
232+
oName.resize(oName.length() - 4);
233+
else
234+
oName = oName + ".bak";
235+
}
236+
}
237+
238+
_ctx.putString("inputName", iName);
239+
_ctx.putString("outputName", oName);
240+
FileDecompressTask<FileDecompressResult> task(_ctx, _listeners);
241+
FileDecompressResult fdr = task.run();
242+
res = fdr._code;
243+
read = fdr._read;
244+
245+
if (res != 0) {
246+
cerr << fdr._errMsg << endl;
247+
}
248+
}
249+
else {
208250
vector<FileDecompressTask<FileDecompressResult>*> tasks;
209251
vector<int> jobsPerTask(nbFiles);
210252
Global::computeJobsPerTask(jobsPerTask.data(), _jobs, nbFiles);

0 commit comments

Comments
 (0)