[PATCH] CRC-32 from zlib
Yuriy Skalko
yuriy.skalko at gmail.com
Mon Dec 28 14:16:36 UTC 2020
zlib has implementation of crc32 algorithm, I've used it instead of
Boost's one.
Now another part of Boost can be thrown away :)
Yuriy
-------------- next part --------------
From ec7563f53dc84f80bef4ba067a61d7ec5a9d4bac Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.skalko at gmail.com>
Date: Sat, 26 Dec 2020 21:23:44 +0200
Subject: [PATCH 7/7] Use crc32 calculation from zlib instead of boost
---
src/support/FileName.cpp | 4 ++--
src/support/checksum.cpp | 25 +++++++++++++------------
src/support/checksum.h | 2 +-
3 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp
index 3d31c7d37c..5295741e1a 100644
--- a/src/support/FileName.cpp
+++ b/src/support/FileName.cpp
@@ -608,8 +608,8 @@ unsigned long FileName::checksum() const
return 0;
}
- char * beg = static_cast<char*>(mm);
- char * end = beg + info.st_size;
+ unsigned char * beg = static_cast<unsigned char*>(mm);
+ unsigned char * end = beg + info.st_size;
result = support::checksum(beg, end);
diff --git a/src/support/checksum.cpp b/src/support/checksum.cpp
index 79ef955ce3..2249ad14e0 100644
--- a/src/support/checksum.cpp
+++ b/src/support/checksum.cpp
@@ -9,9 +9,10 @@
* Full author contact details are available in file CREDITS.
*/
+#include <config.h>
#include "support/checksum.h"
-#include "boost/crc.hpp"
-#include <algorithm>
+
+#include <zlib.h>
namespace lyx {
@@ -19,9 +20,8 @@ namespace support {
unsigned long checksum(std::string const & s)
{
- boost::crc_32_type crc;
- crc.process_bytes(s.c_str(), s.size());
- return crc.checksum();
+ auto p = reinterpret_cast<unsigned char const *>(s.c_str());
+ return crc32(0, p, s.size());
}
unsigned long checksum(std::ifstream & ifs)
@@ -29,16 +29,17 @@ unsigned long checksum(std::ifstream & ifs)
std::istreambuf_iterator<char> beg(ifs);
std::istreambuf_iterator<char> end;
- boost::crc_32_type crc;
- crc = for_each(beg, end, crc);
- return crc.checksum();
+ unsigned long sum = 0;
+ for (auto & it = beg; beg != end; ++it) {
+ unsigned char c = *it;
+ sum = crc32(sum, &c, 1);
+ }
+ return sum;
}
-unsigned long checksum(char const * beg, char const * end)
+unsigned long checksum(unsigned char const * beg, unsigned char const * end)
{
- boost::crc_32_type crc;
- crc.process_block(beg, end);
- return crc.checksum();
+ return crc32(0, beg, end - beg);
}
} // namespace support
diff --git a/src/support/checksum.h b/src/support/checksum.h
index ab14339765..0533c57d79 100644
--- a/src/support/checksum.h
+++ b/src/support/checksum.h
@@ -21,7 +21,7 @@ namespace support {
unsigned long checksum(std::string const & s);
unsigned long checksum(std::ifstream & ifs);
-unsigned long checksum(char const * beg, char const * end);
+unsigned long checksum(unsigned char const * beg, unsigned char const * end);
} // namespace support
--
2.28.0.windows.1
More information about the lyx-devel
mailing list