remove use of std::to_string in favor of boost::lexical_cast

std::to_string calls sprintf() internally, which is really slow
This commit is contained in:
Konstantin Käfer
2014-12-04 12:59:09 +01:00
parent 65451187f5
commit b449b22abc
11 changed files with 45 additions and 29 deletions

View File

@@ -44,10 +44,6 @@ public:
return ((std::pow(2, z) * y + x) * 32) + z;
}
inline operator std::string() const {
return std::to_string(z) + "/" + std::to_string(x) + "/" + std::to_string(y);
}
inline bool operator==(const ID& rhs) const {
return w == rhs.w && z == rhs.z && x == rhs.x && y == rhs.y;
}
@@ -67,6 +63,7 @@ public:
ID normalized() const;
std::forward_list<ID> children(int32_t z) const;
bool isChildOf(const Tile::ID &id) const;
operator std::string() const;
};
static std::forward_list<Tile::ID> cover(int8_t z, const box& bounds);

View File

@@ -3,9 +3,27 @@
#include <string>
#pragma GCC diagnostic push
#ifndef __clang__
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#endif
#include <boost/lexical_cast.hpp>
#pragma GCC diagnostic pop
namespace mbgl {
namespace util {
template <typename... Args>
inline std::string toString(Args&&... args) {
return boost::lexical_cast<std::string>(::std::forward<Args>(args)...);
}
// boost::lexical_cast() treats this as a character, but we are using it as number types.
inline std::string toString(int8_t num) {
return boost::lexical_cast<std::string>(int(num));
}
template<size_t max, typename... Args>
inline std::string sprintf(const char *msg, Args... args) {
char res[max];