Skip to content

Commit

Permalink
[core] Minor optimizations ; support comments and trailing commas in …
Browse files Browse the repository at this point in the history
…parsed json
  • Loading branch information
jcelerier committed Mar 21, 2024
1 parent 708aab1 commit eb3bf4b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,22 @@ if(OSSIA_QT)
find_package(${QT_VERSION} QUIET ${OSSIA_QT_REQUIRED} COMPONENTS Quick)
endif()

if(TARGET Qt${QT_VERSION_MAJOR}::Core)
if(TARGET "Qt${QT_VERSION_MAJOR}::Core")
set(OSSIA_QT ON)
else()
set(OSSIA_QT OFF)
endif()
if(TARGET Qt${QT_VERSION_MAJOR}::Qml)
if(TARGET "Qt${QT_VERSION_MAJOR}::Qml")
set(OSSIA_QML ON)
else()
set(OSSIA_QML OFF)
endif()
if(NOT TARGET Qt${QT_VERSION_MAJOR}::Core)
if(NOT TARGET "Qt${QT_VERSION_MAJOR}::Core")
set(OSSIA_QML_DEVICE OFF)
endif()
if(NOT DEFINED OSSIA_QML_DEVICE)
set(OSSIA_QML_DEVICE 1)
endif()

endif()

### Library ###
Expand Down
12 changes: 10 additions & 2 deletions src/ossia/detail/algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ auto find_if(Vector&& v, Fun fun)
template <typename Vector, typename Value>
auto* ptr_find(Vector&& v, const Value& val) noexcept
{
auto it = std::find(std::begin(v), std::end(v), val);
return it != std::end(v) ? &*it : nullptr;
if constexpr(requires { v.find(val) != v.end(); })
{
auto it = v.find(val);
return it != v.end() ? &it->second : nullptr;
}
else
{
auto it = std::find(std::begin(v), std::end(v), val);
return it != std::end(v) ? &*it : nullptr;
}
}

template <typename Vector, typename Fun>
Expand Down
3 changes: 2 additions & 1 deletion src/ossia/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
#if defined(RAPIDJSON_PARSE_DEFAULT_FLAGS)
#error Include <ossia/detail/json.hpp> to use JSON
#endif
#define RAPIDJSON_PARSE_DEFAULT_FLAGS kParseNanAndInfFlag
#define RAPIDJSON_PARSE_DEFAULT_FLAGS \
kParseCommentsFlag | kParseTrailingCommasFlag | kParseNanAndInfFlag

#if !defined(BOOST_MATH_DISABLE_FLOAT128)
#define BOOST_MATH_DISABLE_FLOAT128
Expand Down

0 comments on commit eb3bf4b

Please sign in to comment.