package An official xmake package repository
https://xrepo.xmake.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.7 KiB
88 lines
2.7 KiB
11 months ago
|
diff --git a/cartographer/common/port.h b/cartographer/common/port.h
|
||
|
index 338861f..252c566 100644
|
||
|
--- a/cartographer/common/port.h
|
||
|
+++ b/cartographer/common/port.h
|
||
|
@@ -19,11 +19,12 @@
|
||
|
|
||
|
#include <cinttypes>
|
||
|
#include <cmath>
|
||
|
+#include <cstring>
|
||
|
#include <string>
|
||
|
+#include <stdexcept>
|
||
|
+#include <functional>
|
||
|
|
||
|
-#include <boost/iostreams/device/back_inserter.hpp>
|
||
|
-#include <boost/iostreams/filter/gzip.hpp>
|
||
|
-#include <boost/iostreams/filtering_stream.hpp>
|
||
|
+#include <zlib.h>
|
||
|
|
||
|
namespace cartographer {
|
||
|
|
||
|
@@ -48,22 +49,54 @@ inline int64 RoundToInt64(const double x) { return std::lround(x); }
|
||
|
|
||
|
inline void FastGzipString(const std::string& uncompressed,
|
||
|
std::string* compressed) {
|
||
|
- boost::iostreams::filtering_ostream out;
|
||
|
- out.push(
|
||
|
- boost::iostreams::gzip_compressor(boost::iostreams::zlib::best_speed));
|
||
|
- out.push(boost::iostreams::back_inserter(*compressed));
|
||
|
- boost::iostreams::write(out,
|
||
|
- reinterpret_cast<const char*>(uncompressed.data()),
|
||
|
- uncompressed.size());
|
||
|
+ z_stream zs;
|
||
|
+ memset(&zs, 0, sizeof(zs));
|
||
|
+
|
||
|
+ if (deflateInit(&zs, Z_BEST_SPEED) != Z_OK)
|
||
|
+ throw std::runtime_error("deflateInit failed while compressing.");
|
||
|
+
|
||
|
+ zs.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(uncompressed.data()));
|
||
|
+ zs.avail_in = static_cast<uInt>(uncompressed.size());
|
||
|
+
|
||
|
+ int ret;
|
||
|
+ char buffer[4096];
|
||
|
+
|
||
|
+ do {
|
||
|
+ zs.next_out = reinterpret_cast<Bytef*>(buffer);
|
||
|
+ zs.avail_out = sizeof(buffer);
|
||
|
+
|
||
|
+ ret = deflate(&zs, Z_FINISH);
|
||
|
+
|
||
|
+ compressed->append(buffer, sizeof(buffer) - zs.avail_out);
|
||
|
+ } while (zs.avail_out == 0);
|
||
|
+
|
||
|
+ deflateEnd(&zs);
|
||
|
}
|
||
|
|
||
|
inline void FastGunzipString(const std::string& compressed,
|
||
|
std::string* decompressed) {
|
||
|
- boost::iostreams::filtering_ostream out;
|
||
|
- out.push(boost::iostreams::gzip_decompressor());
|
||
|
- out.push(boost::iostreams::back_inserter(*decompressed));
|
||
|
- boost::iostreams::write(out, reinterpret_cast<const char*>(compressed.data()),
|
||
|
- compressed.size());
|
||
|
+ z_stream zs;
|
||
|
+ memset(&zs, 0, sizeof(zs));
|
||
|
+
|
||
|
+ if (inflateInit(&zs) != Z_OK)
|
||
|
+ throw std::runtime_error("inflateInit failed while decompressing.");
|
||
|
+
|
||
|
+ zs.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(compressed.data()));
|
||
|
+ zs.avail_in = static_cast<uInt>(compressed.size());
|
||
|
+
|
||
|
+ int ret;
|
||
|
+ char buffer[4096];
|
||
|
+
|
||
|
+ do {
|
||
|
+ zs.next_out = reinterpret_cast<Bytef*>(buffer);
|
||
|
+ zs.avail_out = sizeof(buffer);
|
||
|
+
|
||
|
+ ret = inflate(&zs, Z_NO_FLUSH);
|
||
|
+
|
||
|
+ decompressed->append(buffer, sizeof(buffer) - zs.avail_out);
|
||
|
+ } while (zs.avail_out == 0);
|
||
|
+
|
||
|
+ inflateEnd(&zs);
|
||
|
}
|
||
|
|
||
|
} // namespace common
|