]> git.lyx.org Git - lyx.git/commitdiff
Use crc32 calculation from zlib instead of boost
authorYuriy Skalko <yuriy.skalko@gmail.com>
Sat, 26 Dec 2020 19:23:44 +0000 (21:23 +0200)
committerYuriy Skalko <yuriy.skalko@gmail.com>
Mon, 28 Dec 2020 19:32:56 +0000 (21:32 +0200)
src/support/FileName.cpp
src/support/checksum.cpp
src/support/checksum.h

index 3d31c7d37c607d971a4639d0c0ca2510ac9cd7c4..5295741e1abc9faafc404695d73356edcc6583ff 100644 (file)
@@ -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);
 
index 79ef955ce3ca14aaa6d504e184ccf44dc9dddfae..2249ad14e06e86b707c3f50cf91c038b84f8110e 100644 (file)
@@ -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
index ab14339765a2e4fa1144c7f084a9fc9c4578c085..0533c57d793cd2f186f7a974a95df6ecf1fefb8a 100644 (file)
@@ -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