Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/include/join/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include <cstddef>
#include <cstring>

#define JOIN_ALWAYS_INLINE inline __attribute__ ((always_inline))

#define JOIN_LIKELY(x) __builtin_expect (!!(x), 1)
#define JOIN_UNLIKELY(x) __builtin_expect (!!(x), 0)

Expand Down
45 changes: 22 additions & 23 deletions data/include/join/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ namespace join
virtual int setNull () override
{
array ();
append4 ("null");
append ("null", 4);
_first = false;
return 0;
}
Expand All @@ -217,11 +217,11 @@ namespace join
array ();
if (value)
{
append4 ("true");
append ("true", 4);
}
else
{
append5 ("false");
append ("false", 5);
}
_first = false;
return 0;
Expand Down Expand Up @@ -300,22 +300,22 @@ namespace join
{
if (neg)
{
append4 ("-NaN");
append ("-NaN", 4);
}
else
{
append3 ("NaN");
append ("NaN", 3);
}
}
else
{
if (neg)
{
append4 ("-Inf");
append ("-Inf", 4);
}
else
{
append3 ("Inf");
append ("Inf", 3);
}
}
_first = false;
Expand Down Expand Up @@ -576,7 +576,7 @@ namespace join
else
{
char escapeSeq[2] = {'\\', static_cast<char> (esc)};
append2 (escapeSeq);
append (escapeSeq, 2);
}

++cur;
Expand Down Expand Up @@ -729,7 +729,7 @@ namespace join
}
else
{
append4 ("null");
append ("null", 4);
}
_first = false;
return 0;
Expand Down Expand Up @@ -1115,6 +1115,8 @@ namespace join
template <JsonReadMode ReadMode, typename ViewType>
int read (ViewType& document)
{
_depth = 0;

if (skipWhitespaces<ReadMode> (document) != 0)
{
return -1;
Expand Down Expand Up @@ -1455,8 +1457,7 @@ namespace join
}
else if (JOIN_LIKELY (isDigit (view.peek ())))
{
u = view.get () - '0';
++digits;
digits = view.readDigits (u, 18);

while (JOIN_LIKELY (isDigit (view.peek ())))
{
Expand Down Expand Up @@ -1488,27 +1489,25 @@ namespace join

if (isDouble)
{
while (JOIN_LIKELY (isDigit (view.peek ())))
{
u = (u * 10) + (view.get () - '0');
++digits;
}
digits += view.readDigits (u);
}

int64_t frac = 0;
if (view.getIf ('.'))
{
isDouble = true;

while (JOIN_LIKELY (isDigit (view.peek ())))
if (JOIN_UNLIKELY (digits == 0))
{
u = (u * 10) + (view.get () - '0');
if (JOIN_LIKELY (u || digits))
while (view.getIf ('0'))
{
++digits;
--frac;
}
--frac;
}

size_t count = view.readDigits (u);
digits += count;
frac -= static_cast<int64_t> (count);
}

int64_t exponent = 0;
Expand Down Expand Up @@ -1767,7 +1766,7 @@ namespace join
* @return 0 on success, -1 otherwise.
*/
template <JsonReadMode ReadMode, typename ViewType>
int readArray (ViewType& document)
JOIN_ALWAYS_INLINE int readArray (ViewType& document)
{
if (JOIN_UNLIKELY (startArray () == -1))
{
Expand Down Expand Up @@ -1829,7 +1828,7 @@ namespace join
* @return 0 on success, -1 otherwise.
*/
template <JsonReadMode ReadMode, typename ViewType>
int readObject (ViewType& document)
JOIN_ALWAYS_INLINE int readObject (ViewType& document)
{
if (JOIN_UNLIKELY (startObject () == -1))
{
Expand Down
20 changes: 18 additions & 2 deletions data/include/join/pack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ namespace join
template <typename ViewType>
int read (ViewType& document)
{
_depth = 0;

if (JOIN_LIKELY (readValue (document) == 0))
{
if (JOIN_LIKELY (document.peek () == std::char_traits<char>::eof ()))
Expand All @@ -572,7 +574,14 @@ namespace join
template <typename ViewType>
int readValue (ViewType& document)
{
uint8_t head = static_cast<uint8_t> (document.peek ());
int ch = document.peek ();
if (JOIN_UNLIKELY (ch == std::char_traits<char>::eof ()))
{
join::lastError = make_error_code (SaxErrc::InvalidValue);
return -1;
}

uint8_t head = static_cast<uint8_t> (ch);

try
{
Expand Down Expand Up @@ -755,7 +764,14 @@ namespace join
template <typename ViewType>
int readKey (ViewType& document)
{
uint8_t head = static_cast<uint8_t> (document.peek ());
int ch = document.peek ();
if (JOIN_UNLIKELY (ch == std::char_traits<char>::eof ()))
{
join::lastError = make_error_code (SaxErrc::InvalidValue);
return -1;
}

uint8_t head = static_cast<uint8_t> (ch);

try
{
Expand Down
Loading
Loading