Skip to content

Commit

Permalink
Remove assert() and timer
Browse files Browse the repository at this point in the history
 - Move filename compare function to file I/O subsystem.
  • Loading branch information
t-mat committed Aug 22, 2013
1 parent c0e1210 commit 02910e3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
11 changes: 11 additions & 0 deletions src/lz4mt_io_cstdio.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
Expand Down Expand Up @@ -201,4 +202,14 @@ bool isAttyStdout() {
#endif
}

bool compareFilename(const std::string& lhs, const std::string& rhs) {
const auto l = lhs.c_str();
const auto r = rhs.c_str();
#if defined(_WIN32)
return 0 == _stricmp(l, r);
#else
return 0 == strcmp(l, r);
#endif
}

}} // namespace Cstdio, Lz4Mt
1 change: 1 addition & 0 deletions src/lz4mt_io_cstdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ std::string getStdoutFilename();
std::string getNullFilename();
bool isAttyStdin();
bool isAttyStdout();
bool compareFilename(const std::string& lhs, const std::string& rhs);

}}

Expand Down
40 changes: 14 additions & 26 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <cassert>
#include <functional>
#include <iostream>
#include <map>
Expand All @@ -14,11 +13,9 @@
#endif
#include "lz4.h"
#include "lz4hc.h"
#include "xxhash.h"
#include "lz4mt.h"
#include "lz4mt_benchmark.h"
#include "lz4mt_io_cstdio.h"
#include "test_clock.h"


namespace {
Expand Down Expand Up @@ -53,14 +50,20 @@ const char usage_advanced[] =
" output : can be 'stdout'(pipe) or a filename or 'null'\n"
;

typedef std::function<bool(void)> AttyFunc;
typedef std::function<bool(const std::string&, const std::string&)> CmpFunc;

struct Option {
Option(int argc, char* argv[]
, std::string stdinFilename
, std::string stdoutFilename
, std::string nullFilename
, std::function<bool(void)> isAttyStdout
, std::function<bool(void)> isAttyStdin
)
Option(
int argc
, char* argv[]
, std::string stdinFilename
, std::string stdoutFilename
, std::string nullFilename
, AttyFunc isAttyStdout
, AttyFunc isAttyStdin
, CmpFunc cmpFilename
)
: error(false)
, exitFlag(false)
, compMode(CompMode::COMPRESS_C0)
Expand Down Expand Up @@ -273,16 +276,6 @@ struct Option {
return CompMode::DECOMPRESS == compMode;
}

static bool cmpFilename(const std::string& lhs, const std::string& rhs) {
const auto pLhs = lhs.c_str();
const auto pRhs = rhs.c_str();
#if defined(_WIN32)
return 0 == _stricmp(pLhs, pRhs);
#else
return 0 == strcmp(pLhs, pRhs);
#endif
}

void showUsage(bool advanced = false) {
errorString += usage;
if(advanced) {
Expand Down Expand Up @@ -345,6 +338,7 @@ int main(int argc, char* argv[]) {
, getNullFilename()
, isAttyStdout
, isAttyStdin
, compareFilename
);

if(opt.exitFlag) {
Expand Down Expand Up @@ -403,26 +397,20 @@ int main(int argc, char* argv[]) {
exit(EXIT_FAILURE);
}

const auto t0 = Clock::now();
const auto e = [&]() -> Lz4MtResult {
if(opt.isCompress()) {
return lz4mtCompress(&ctx, &opt.sd);
} else if(opt.isDecompress()) {
return lz4mtDecompress(&ctx, &opt.sd);
} else {
assert(0);
opt.display("lz4mt: You must specify a switch -c or -d\n");
return LZ4MT_RESULT_BAD_ARG;
}
} ();
const auto t1 = Clock::now();

closeOstream(&ctx);
closeIstream(&ctx);

const auto dt = std::chrono::duration_cast<std::chrono::duration<double>>(t1 - t0).count();
opt.display("Total time: " + std::to_string(dt) + "sec\n");

if(LZ4MT_RESULT_OK != e) {
opt.display("lz4mt: " + std::string(lz4mtResultToString(e)) + "\n");
exit(EXIT_FAILURE);
Expand Down

0 comments on commit 02910e3

Please sign in to comment.