2
0

remove-boost.patch 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. diff --git a/cartographer/common/port.h b/cartographer/common/port.h
  2. index 338861f..252c566 100644
  3. --- a/cartographer/common/port.h
  4. +++ b/cartographer/common/port.h
  5. @@ -19,11 +19,12 @@
  6. #include <cinttypes>
  7. #include <cmath>
  8. +#include <cstring>
  9. #include <string>
  10. +#include <stdexcept>
  11. +#include <functional>
  12. -#include <boost/iostreams/device/back_inserter.hpp>
  13. -#include <boost/iostreams/filter/gzip.hpp>
  14. -#include <boost/iostreams/filtering_stream.hpp>
  15. +#include <zlib.h>
  16. namespace cartographer {
  17. @@ -48,22 +49,54 @@ inline int64 RoundToInt64(const double x) { return std::lround(x); }
  18. inline void FastGzipString(const std::string& uncompressed,
  19. std::string* compressed) {
  20. - boost::iostreams::filtering_ostream out;
  21. - out.push(
  22. - boost::iostreams::gzip_compressor(boost::iostreams::zlib::best_speed));
  23. - out.push(boost::iostreams::back_inserter(*compressed));
  24. - boost::iostreams::write(out,
  25. - reinterpret_cast<const char*>(uncompressed.data()),
  26. - uncompressed.size());
  27. + z_stream zs;
  28. + memset(&zs, 0, sizeof(zs));
  29. +
  30. + if (deflateInit(&zs, Z_BEST_SPEED) != Z_OK)
  31. + throw std::runtime_error("deflateInit failed while compressing.");
  32. +
  33. + zs.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(uncompressed.data()));
  34. + zs.avail_in = static_cast<uInt>(uncompressed.size());
  35. +
  36. + int ret;
  37. + char buffer[4096];
  38. +
  39. + do {
  40. + zs.next_out = reinterpret_cast<Bytef*>(buffer);
  41. + zs.avail_out = sizeof(buffer);
  42. +
  43. + ret = deflate(&zs, Z_FINISH);
  44. +
  45. + compressed->append(buffer, sizeof(buffer) - zs.avail_out);
  46. + } while (zs.avail_out == 0);
  47. +
  48. + deflateEnd(&zs);
  49. }
  50. inline void FastGunzipString(const std::string& compressed,
  51. std::string* decompressed) {
  52. - boost::iostreams::filtering_ostream out;
  53. - out.push(boost::iostreams::gzip_decompressor());
  54. - out.push(boost::iostreams::back_inserter(*decompressed));
  55. - boost::iostreams::write(out, reinterpret_cast<const char*>(compressed.data()),
  56. - compressed.size());
  57. + z_stream zs;
  58. + memset(&zs, 0, sizeof(zs));
  59. +
  60. + if (inflateInit(&zs) != Z_OK)
  61. + throw std::runtime_error("inflateInit failed while decompressing.");
  62. +
  63. + zs.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(compressed.data()));
  64. + zs.avail_in = static_cast<uInt>(compressed.size());
  65. +
  66. + int ret;
  67. + char buffer[4096];
  68. +
  69. + do {
  70. + zs.next_out = reinterpret_cast<Bytef*>(buffer);
  71. + zs.avail_out = sizeof(buffer);
  72. +
  73. + ret = inflate(&zs, Z_NO_FLUSH);
  74. +
  75. + decompressed->append(buffer, sizeof(buffer) - zs.avail_out);
  76. + } while (zs.avail_out == 0);
  77. +
  78. + inflateEnd(&zs);
  79. }
  80. } // namespace common