Commit 93d52d89 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

use to-ascii array vs table on mobile

Summary: The table is large while the array is small.

Reviewed By: luciang

Differential Revision: D27986020

fbshipit-source-id: b6896514408758c592e2b74d801e38f217163f61
parent ab79b855
...@@ -86,7 +86,7 @@ struct to_ascii_array { ...@@ -86,7 +86,7 @@ struct to_ascii_array {
} }
}; };
template <uint64_t Base, typename Alphabet> template <uint64_t Base, typename Alphabet>
alignas(hardware_constructive_interference_size) alignas(kIsMobile ? sizeof(size_t) : hardware_constructive_interference_size)
typename to_ascii_array<Base, Alphabet>::data_type_ const typename to_ascii_array<Base, Alphabet>::data_type_ const
to_ascii_array<Base, Alphabet>::data = to_ascii_array<Base, Alphabet>::data =
to_ascii_array<Base, Alphabet>::data_(); to_ascii_array<Base, Alphabet>::data_();
...@@ -262,10 +262,10 @@ FOLLY_ALWAYS_INLINE void to_ascii_with_basic( ...@@ -262,10 +262,10 @@ FOLLY_ALWAYS_INLINE void to_ascii_with_basic(
// keep /, % together so a peephole optimization computes them together // keep /, % together so a peephole optimization computes them together
auto const q = v / Base; auto const q = v / Base;
auto const r = v % Base; auto const r = v % Base;
out[pos] = xlate(r); out[pos] = xlate(uint8_t(r));
v = q; v = q;
} }
out[0] = xlate(v); out[0] = xlate(uint8_t(v));
} }
template <uint64_t Base, typename Alphabet> template <uint64_t Base, typename Alphabet>
FOLLY_ALWAYS_INLINE size_t to_ascii_with_basic(char* out, uint64_t v) { FOLLY_ALWAYS_INLINE size_t to_ascii_with_basic(char* out, uint64_t v) {
...@@ -380,8 +380,11 @@ inline size_t to_ascii_size_decimal(uint64_t v) { ...@@ -380,8 +380,11 @@ inline size_t to_ascii_size_decimal(uint64_t v) {
template <uint64_t Base, typename Alphabet> template <uint64_t Base, typename Alphabet>
size_t to_ascii_with(char* outb, char const* oute, uint64_t v) { size_t to_ascii_with(char* outb, char const* oute, uint64_t v) {
auto const size = to_ascii_size<Base>(v); auto const size = to_ascii_size<Base>(v);
return FOLLY_UNLIKELY(oute < outb || size_t(oute - outb) < size) if (FOLLY_UNLIKELY(oute < outb || size_t(oute - outb) < size)) {
? 0 return 0;
}
return kIsMobile //
? detail::to_ascii_with_array<Base, Alphabet>(outb, v)
: detail::to_ascii_with_table<Base, Alphabet>(outb, v); : detail::to_ascii_with_table<Base, Alphabet>(outb, v);
} }
template <uint64_t Base, typename Alphabet, size_t N> template <uint64_t Base, typename Alphabet, size_t N>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment