mirror of
https://github.com/nlohmann/json.git
synced 2026-10-11 08:57:15 +00:00
Fix clang-tidy 22 findings in the json_view headers
Silence bugprone-casting-through-void for the SSE loads (a reinterpret_cast
would trip -Wcast-align=strict), use auto for a cast initialiser, add
parentheses to a mixed expression, and name bugprone-std-namespace-modification
in the NOLINTs of the tuple_size/tuple_element specialisations.
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
(cherry picked from commit 0effbaa7a2)
This commit is contained in:
3 files changed
+10
-10
No files matched your search
@@ -134,7 +134,7 @@ template<typename SizeType, typename IntegerType>
|
|||||||
SizeType to_index(IntegerType idx) noexcept
|
SizeType to_index(IntegerType idx) noexcept
|
||||||
{
|
{
|
||||||
const IntegerType zero = 0;
|
const IntegerType zero = 0;
|
||||||
const auto result = static_cast<SizeType>(idx);
|
const auto result = static_cast<SizeType>(idx); // NOLINT(bugprone-signed-char-misuse,cert-str34-c): idx is an index, not a character
|
||||||
return (idx < zero || static_cast<IntegerType>(result) != idx) ? (std::numeric_limits<SizeType>::max)() : result;
|
return (idx < zero || static_cast<IntegerType>(result) != idx) ? (std::numeric_limits<SizeType>::max)() : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ NLOHMANN_VIEW_ALWAYS_INLINE const unsigned char* vector_plain_run(const unsigned
|
|||||||
return p + (count_trailing_zeros(bits) >> 2u);
|
return p + (count_trailing_zeros(bits) >> 2u);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
const __m128i in = _mm_loadu_si128(static_cast<const __m128i*>(static_cast<const void*>(p)));
|
const __m128i in = _mm_loadu_si128(static_cast<const __m128i*>(static_cast<const void*>(p))); // NOLINT(bugprone-casting-through-void)
|
||||||
const __m128i special = _mm_or_si128(_mm_or_si128(_mm_cmpeq_epi8(in, _mm_set1_epi8('"')), _mm_cmpeq_epi8(in, _mm_set1_epi8('\\'))),
|
const __m128i special = _mm_or_si128(_mm_or_si128(_mm_cmpeq_epi8(in, _mm_set1_epi8('"')), _mm_cmpeq_epi8(in, _mm_set1_epi8('\\'))),
|
||||||
_mm_cmplt_epi8(in, _mm_set1_epi8(0x20)));
|
_mm_cmplt_epi8(in, _mm_set1_epi8(0x20)));
|
||||||
const auto bits = static_cast<std::uint64_t>(static_cast<unsigned>(_mm_movemask_epi8(special)));
|
const auto bits = static_cast<std::uint64_t>(static_cast<unsigned>(_mm_movemask_epi8(special)));
|
||||||
@@ -293,15 +293,15 @@ NLOHMANN_VIEW_SSSE3_TARGET NLOHMANN_VIEW_NOINLINE inline const unsigned char* sc
|
|||||||
#else
|
#else
|
||||||
// the same with SSSE3 (pshufb for the table lookups; nibbles from 16-bit
|
// the same with SSSE3 (pshufb for the table lookups; nibbles from 16-bit
|
||||||
// shifts, as there are no byte shifts)
|
// shifts, as there are no byte shifts)
|
||||||
const __m128i t1h = _mm_loadu_si128(static_cast<const __m128i*>(static_cast<const void*>(lookup::byte_1_high.data())));
|
const __m128i t1h = _mm_loadu_si128(static_cast<const __m128i*>(static_cast<const void*>(lookup::byte_1_high.data()))); // NOLINT(bugprone-casting-through-void)
|
||||||
const __m128i t1l = _mm_loadu_si128(static_cast<const __m128i*>(static_cast<const void*>(lookup::byte_1_low.data())));
|
const __m128i t1l = _mm_loadu_si128(static_cast<const __m128i*>(static_cast<const void*>(lookup::byte_1_low.data()))); // NOLINT(bugprone-casting-through-void)
|
||||||
const __m128i t2h = _mm_loadu_si128(static_cast<const __m128i*>(static_cast<const void*>(lookup::byte_2_high.data())));
|
const __m128i t2h = _mm_loadu_si128(static_cast<const __m128i*>(static_cast<const void*>(lookup::byte_2_high.data()))); // NOLINT(bugprone-casting-through-void)
|
||||||
const __m128i nibble = _mm_set1_epi8(0x0F);
|
const __m128i nibble = _mm_set1_epi8(0x0F);
|
||||||
const __m128i zero = _mm_setzero_si128();
|
const __m128i zero = _mm_setzero_si128();
|
||||||
__m128i prev = zero;
|
__m128i prev = zero;
|
||||||
while (e - block >= 16)
|
while (e - block >= 16)
|
||||||
{
|
{
|
||||||
const __m128i in = _mm_loadu_si128(static_cast<const __m128i*>(static_cast<const void*>(block)));
|
const __m128i in = _mm_loadu_si128(static_cast<const __m128i*>(static_cast<const void*>(block))); // NOLINT(bugprone-casting-through-void)
|
||||||
const __m128i special = _mm_or_si128(_mm_or_si128(_mm_cmpeq_epi8(in, _mm_set1_epi8('"')), _mm_cmpeq_epi8(in, _mm_set1_epi8('\\'))),
|
const __m128i special = _mm_or_si128(_mm_or_si128(_mm_cmpeq_epi8(in, _mm_set1_epi8('"')), _mm_cmpeq_epi8(in, _mm_set1_epi8('\\'))),
|
||||||
_mm_cmpeq_epi8(_mm_subs_epu8(in, _mm_set1_epi8(0x1F)), zero)); // in < 0x20
|
_mm_cmpeq_epi8(_mm_subs_epu8(in, _mm_set1_epi8(0x1F)), zero)); // in < 0x20
|
||||||
const __m128i prev1 = _mm_alignr_epi8(in, prev, 15);
|
const __m128i prev1 = _mm_alignr_epi8(in, prev, 15);
|
||||||
@@ -315,7 +315,7 @@ NLOHMANN_VIEW_SSSE3_TARGET NLOHMANN_VIEW_NOINLINE inline const unsigned char* sc
|
|||||||
const auto err_bits = ~static_cast<unsigned>(_mm_movemask_epi8(_mm_cmpeq_epi8(err, zero))) & 0xFFFFu;
|
const auto err_bits = ~static_cast<unsigned>(_mm_movemask_epi8(_mm_cmpeq_epi8(err, zero))) & 0xFFFFu;
|
||||||
if (special_bits != 0)
|
if (special_bits != 0)
|
||||||
{
|
{
|
||||||
const unsigned k = static_cast<unsigned>(count_trailing_zeros(static_cast<std::uint64_t>(special_bits)));
|
const auto k = static_cast<unsigned>(count_trailing_zeros(static_cast<std::uint64_t>(special_bits)));
|
||||||
if ((err_bits & ((2u << k) - 1u)) == 0)
|
if ((err_bits & ((2u << k) - 1u)) == 0)
|
||||||
{
|
{
|
||||||
return block + k;
|
return block + k;
|
||||||
|
|||||||
@@ -760,7 +760,7 @@ class basic_json_view
|
|||||||
// the end is unknown: assume a few bytes per node, the output buffer
|
// the end is unknown: assume a few bytes per node, the output buffer
|
||||||
// grows should the value be larger
|
// grows should the value be larger
|
||||||
const auto nodes = static_cast<std::size_t>(document_data::after(m_node) - m_node);
|
const auto nodes = static_cast<std::size_t>(document_data::after(m_node) - m_node);
|
||||||
return (std::min)(m_doc->size - m_node->off, static_cast<std::size_t>(1024) + nodes * 16);
|
return (std::min)(m_doc->size - m_node->off, static_cast<std::size_t>(1024) + (nodes * 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// the value of the first member with this key, or a discarded view
|
/// the value of the first member with this key, or a discarded view
|
||||||
@@ -1496,11 +1496,11 @@ namespace std // NOLINT(cert-dcl58-cpp)
|
|||||||
#pragma clang diagnostic ignored "-Wmismatched-tags"
|
#pragma clang diagnostic ignored "-Wmismatched-tags"
|
||||||
#endif
|
#endif
|
||||||
template<typename View>
|
template<typename View>
|
||||||
class tuple_size<::nlohmann::detail::view::view_item<View>> // NOLINT(cert-dcl58-cpp)
|
class tuple_size<::nlohmann::detail::view::view_item<View>> // NOLINT(cert-dcl58-cpp,bugprone-std-namespace-modification)
|
||||||
: public std::integral_constant<std::size_t, 2> {};
|
: public std::integral_constant<std::size_t, 2> {};
|
||||||
|
|
||||||
template<std::size_t N, typename View>
|
template<std::size_t N, typename View>
|
||||||
class tuple_element<N, ::nlohmann::detail::view::view_item<View>> // NOLINT(cert-dcl58-cpp)
|
class tuple_element<N, ::nlohmann::detail::view::view_item<View>> // NOLINT(cert-dcl58-cpp,bugprone-std-namespace-modification)
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using type = decltype(std::declval<::nlohmann::detail::view::view_item<View>>().template get<N>());
|
using type = decltype(std::declval<::nlohmann::detail::view::view_item<View>>().template get<N>());
|
||||||
|
|||||||
Reference in new issue
Block a user