1
0
Fork 0
mirror of https://github.com/KingDuckZ/incredis synced 2024-11-23 00:33:46 +00:00

Don't copy nul-terminators if any.

This commit is contained in:
King_DuckZ 2018-10-13 14:47:28 +01:00
parent dc3f817db5
commit a8a27b307f

View file

@ -66,13 +66,15 @@ namespace redis {
template <typename T> template <typename T>
struct IntConv<T, std::enable_if_t<std::is_integral_v<T>, std::string>> { struct IntConv<T, std::enable_if_t<std::is_integral_v<T>, std::string>> {
static T conv (const std::string& in) { static T conv (const std::string& in) {
return dhandy::ary_to_int<T, char, 10, AsciiTranslator>(in.data(), in.data() + in.size()); const auto size = in.size() - (in.empty() or in.back() ? 0 : 1);
return dhandy::ary_to_int<T, char, 10, AsciiTranslator>(in.data(), in.data() + size);
} }
}; };
template <typename T> template <typename T>
struct IntConv<T, std::enable_if_t<std::is_integral_v<T>, boost::string_view>> { struct IntConv<T, std::enable_if_t<std::is_integral_v<T>, boost::string_view>> {
static T conv (const boost::string_view& in) { static T conv (const boost::string_view& in) {
return dhandy::ary_to_int<T, char, 10, AsciiTranslator>(in.data(), in.data() + in.size()); const auto size = in.size() - (in.empty() or in.back() ? 0 : 1);
return dhandy::ary_to_int<T, char, 10, AsciiTranslator>(in.data(), in.data() + size);
} }
}; };
} //namespace implem } //namespace implem