Skip to content

Commit

Permalink
perf: add const for some operator function
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Jul 22, 2023
1 parent 58dcd7a commit dc3dd62
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions include/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,16 @@ class basic_value
basic_value<string_t>& operator[](const string_t& key);
basic_value<string_t>& operator[](string_t&& key);

basic_value<string_t> operator|(const basic_object<string_t>& rhs) &;
basic_value<string_t> operator|(basic_object<string_t>&& rhs) &;
basic_value<string_t> operator|(const basic_object<string_t>& rhs) const&;
basic_value<string_t> operator|(basic_object<string_t>&& rhs) const&;
basic_value<string_t> operator|(const basic_object<string_t>& rhs) &&;
basic_value<string_t> operator|(basic_object<string_t>&& rhs) &&;

basic_value<string_t>& operator|=(const basic_object<string_t>& rhs);
basic_value<string_t>& operator|=(basic_object<string_t>&& rhs);

basic_value<string_t> operator+(const basic_array<string_t>& rhs) &;
basic_value<string_t> operator+(basic_array<string_t>&& rhs) &;
basic_value<string_t> operator+(const basic_array<string_t>& rhs) const&;
basic_value<string_t> operator+(basic_array<string_t>&& rhs) const&;
basic_value<string_t> operator+(const basic_array<string_t>& rhs) &&;
basic_value<string_t> operator+(basic_array<string_t>&& rhs) &&;

Expand Down Expand Up @@ -324,8 +324,8 @@ class basic_array
const basic_value<string_t>& operator[](size_t pos) const;
basic_value<string_t>& operator[](size_t pos);

basic_array<string_t> operator+(const basic_array<string_t>& rhs) &;
basic_array<string_t> operator+(basic_array<string_t>&& rhs) &;
basic_array<string_t> operator+(const basic_array<string_t>& rhs) const&;
basic_array<string_t> operator+(basic_array<string_t>&& rhs) const&;
basic_array<string_t> operator+(const basic_array<string_t>& rhs) &&;
basic_array<string_t> operator+(basic_array<string_t>&& rhs) &&;

Expand Down Expand Up @@ -430,8 +430,8 @@ class basic_object
basic_value<string_t>& operator[](const string_t& key);
basic_value<string_t>& operator[](string_t&& key);

basic_object<string_t> operator|(const basic_object<string_t>& rhs) &;
basic_object<string_t> operator|(basic_object<string_t>&& rhs) &;
basic_object<string_t> operator|(const basic_object<string_t>& rhs) const&;
basic_object<string_t> operator|(basic_object<string_t>&& rhs) const&;
basic_object<string_t> operator|(const basic_object<string_t>& rhs) &&;
basic_object<string_t> operator|(basic_object<string_t>&& rhs) &&;

Expand Down Expand Up @@ -463,7 +463,8 @@ class basic_object
// * parser declare *
// ****************************

template <typename string_t = default_string_t, typename parsing_t = void, typename accel_traits = packed_bytes_trait_max>
template <typename string_t = default_string_t, typename parsing_t = void,
typename accel_traits = packed_bytes_trait_max>
class parser
{
public:
Expand Down Expand Up @@ -1212,13 +1213,13 @@ MEOJSON_INLINE basic_value<string_t>& basic_value<string_t>::operator[](string_t
}

template <typename string_t>
MEOJSON_INLINE basic_value<string_t> basic_value<string_t>::operator|(const basic_object<string_t>& rhs) &
MEOJSON_INLINE basic_value<string_t> basic_value<string_t>::operator|(const basic_object<string_t>& rhs) const&
{
return as_object() | rhs;
}

template <typename string_t>
MEOJSON_INLINE basic_value<string_t> basic_value<string_t>::operator|(basic_object<string_t>&& rhs) &
MEOJSON_INLINE basic_value<string_t> basic_value<string_t>::operator|(basic_object<string_t>&& rhs) const&
{
return as_object() | std::move(rhs);
}
Expand Down Expand Up @@ -1250,13 +1251,13 @@ MEOJSON_INLINE basic_value<string_t>& basic_value<string_t>::operator|=(basic_ob
}

template <typename string_t>
MEOJSON_INLINE basic_value<string_t> basic_value<string_t>::operator+(const basic_array<string_t>& rhs) &
MEOJSON_INLINE basic_value<string_t> basic_value<string_t>::operator+(const basic_array<string_t>& rhs) const&
{
return as_array() + rhs;
}

template <typename string_t>
MEOJSON_INLINE basic_value<string_t> basic_value<string_t>::operator+(basic_array<string_t>&& rhs) &
MEOJSON_INLINE basic_value<string_t> basic_value<string_t>::operator+(basic_array<string_t>&& rhs) const&
{
return as_array() + std::move(rhs);
}
Expand Down Expand Up @@ -1580,15 +1581,15 @@ MEOJSON_INLINE const basic_value<string_t>& basic_array<string_t>::operator[](si
}

template <typename string_t>
MEOJSON_INLINE basic_array<string_t> basic_array<string_t>::operator+(const basic_array<string_t>& rhs) &
MEOJSON_INLINE basic_array<string_t> basic_array<string_t>::operator+(const basic_array<string_t>& rhs) const&
{
basic_array<string_t> temp = *this;
temp._array_data.insert(_array_data.end(), rhs.begin(), rhs.end());
return temp;
}

template <typename string_t>
MEOJSON_INLINE basic_array<string_t> basic_array<string_t>::operator+(basic_array<string_t>&& rhs) &
MEOJSON_INLINE basic_array<string_t> basic_array<string_t>::operator+(basic_array<string_t>&& rhs) const&
{
basic_array<string_t> temp = *this;
temp._array_data.insert(_array_data.end(), std::make_move_iterator(rhs.begin()),
Expand Down Expand Up @@ -1865,15 +1866,15 @@ MEOJSON_INLINE basic_value<string_t>& basic_object<string_t>::operator[](string_
}

template <typename string_t>
MEOJSON_INLINE basic_object<string_t> basic_object<string_t>::operator|(const basic_object<string_t>& rhs) &
MEOJSON_INLINE basic_object<string_t> basic_object<string_t>::operator|(const basic_object<string_t>& rhs) const&
{
basic_object<string_t> temp = *this;
temp._object_data.insert(rhs.begin(), rhs.end());
return temp;
}

template <typename string_t>
MEOJSON_INLINE basic_object<string_t> basic_object<string_t>::operator|(basic_object<string_t>&& rhs) &
MEOJSON_INLINE basic_object<string_t> basic_object<string_t>::operator|(basic_object<string_t>&& rhs) const&
{
basic_object<string_t> temp = *this;
// temp._object_data.merge(std::move(rhs._object_data));
Expand Down Expand Up @@ -1921,7 +1922,8 @@ MEOJSON_INLINE bool basic_object<string_t>::operator==(const basic_object<string
// *************************

template <typename string_t, typename parsing_t, typename accel_traits>
MEOJSON_INLINE std::optional<basic_value<string_t>> parser<string_t, parsing_t, accel_traits>::parse(const parsing_t& content)
MEOJSON_INLINE std::optional<basic_value<string_t>> parser<string_t, parsing_t, accel_traits>::parse(
const parsing_t& content)
{
return parser<string_t, parsing_t, accel_traits>(content.cbegin(), content.cend()).parse();
}
Expand Down Expand Up @@ -2275,7 +2277,8 @@ MEOJSON_INLINE std::optional<string_t> parser<string_t, parsing_t, accel_traits>
}

template <typename string_t, typename parsing_t, typename accel_traits>
MEOJSON_INLINE void parser<string_t, parsing_t, accel_traits>::skip_string_literal() {
MEOJSON_INLINE void parser<string_t, parsing_t, accel_traits>::skip_string_literal()
{
if constexpr (sizeof(*_cur) != 1) {
return;
}
Expand All @@ -2286,7 +2289,8 @@ MEOJSON_INLINE void parser<string_t, parsing_t, accel_traits>::skip_string_liter
result = accel_traits::bitwise_or(result, accel_traits::equal(pack, static_cast<uint8_t>('\\')));
if (accel_traits::is_all_zero(result)) {
_cur += accel_traits::step;
} else {
}
else {
auto index = accel_traits::first_nonzero_byte(result);
_cur += index;
break;
Expand Down

0 comments on commit dc3dd62

Please sign in to comment.