remove-boost.patch 2.8 KB

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