Skip to content

Commit

Permalink
Jsonifier Release v0.9.8
Browse files Browse the repository at this point in the history
-Improved the Vector classes' implementation.
-Improved the collectEscapedCharacters function.
-Implemented the fallback logic.
  • Loading branch information
RealTimeChris committed Sep 15, 2023
1 parent 790d763 commit f835921
Show file tree
Hide file tree
Showing 35 changed files with 1,734 additions and 2,146 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build-and-Test-GCC-Ubuntu
name: Build-and-Test-CLANG-Ubuntu

on:
push:
Expand All @@ -13,20 +13,24 @@ jobs:
strategy:
fail-fast: false
matrix:
gcc: [12]
clang: [18]
build_type: [Debug, Release]
std: [20]
env:
CC: gcc-${{matrix.gcc}}
CXX: g++-${{matrix.gcc}}

steps:
- uses: actions/checkout@v3

- name: Install the latest Clang compiler.
working-directory: Tests
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 18
- name: Configure CMake
working-directory: Tests
run: |
cmake -S . -B ./Build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DGITHUB_BRANCH_TYPE=${{github.ref}}
cmake -S . -B ./Build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_COMPILER=/usr/bin/clang++-18 -DGITHUB_BRANCH_TYPE=${{github.ref}}
- name: Build the Test
working-directory: Tests/Build
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build-and-Test-CLANG-MacOS
name: Build-and-Test-GCC-MacOS

on:
push:
Expand All @@ -13,24 +13,22 @@ jobs:
strategy:
fail-fast: false
matrix:
clang: [17]
gcc: [13]
build_type: [Debug, Release]
std: [20]

steps:
- uses: actions/checkout@v3

- name: Install Clang17
- name: Install the latest g++ compiler.
run: |
brew install llvm
echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"
brew install gcc
- name: Configure CMake
working-directory: Tests
run: |
cmake -S . -B ./Build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm/bin/clang-16 -DGITHUB_BRANCH_TYPE=${{github.ref}}
cmake -S . -B ./Build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_COMPILER=/usr/local/opt/gcc@13/bin/g++-13 -DGITHUB_BRANCH_TYPE=${{github.ref}}
- name: Build the Test
working-directory: Tests/Build
Expand Down
1 change: 1 addition & 0 deletions CMake/DetectArchitecture.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ endif()

set(CMAKE_REQUIRED_FLAGS_SAVE "${CMAKE_REQUIRED_FLAGS}")

set(AVX_FLAG "-march=native")
set(AVX_TYPE "T_Fallback")

if ((${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "i386") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64"))
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,21 @@ target_compile_options(
"$<$<CXX_COMPILER_ID:MSVC>:/GL>"
"$<$<CXX_COMPILER_ID:GNU>:-pedantic>"
"$<$<CXX_COMPILER_ID:CLANG>:-pedantic>"
"$<$<CXX_COMPILER_ID:CLANG>:-I/usr/local/opt/llvm/include/c++/v1/>"
"$<$<CXX_COMPILER_ID:CLANG>:-I/usr/local/opt/llvm/include>"
"${AVX_FLAG}"
)

target_link_options(
"${PROJECT_NAME}" INTERFACE
"$<$<CXX_COMPILER_ID:GNU>:$<$<STREQUAL:${ASAN_ENABLED},TRUE>:-fsanitize=address>>"
"$<$<CXX_COMPILER_ID:CLANG>:-Wl,-rpath,/usr/local/opt/llvm/lib>"
"$<$<CXX_COMPILER_ID:CLANG>:-L/usr/local/opt/llvm/lib>"
)

target_link_libraries(
"${PROJECT_NAME}" INTERFACE
"$<$<CXX_COMPILER_ID:CLANG>:-lc++>"
)

set(CONFIG_FILE_NAME "${PROJECT_NAME}Config.cmake")
Expand Down
53 changes: 30 additions & 23 deletions Include/jsonifier/Allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,57 @@
#include <memory_resource>
#include <utility>

#if defined(_MSC_VER)
#define ALIGNED_ALLOC(size, alignment) _aligned_malloc(size, alignment)
#define ALIGNED_FREE(ptr) _aligned_free(ptr)
#else
#define ALIGNED_ALLOC(size, alignment) aligned_alloc(alignment, size)
#define ALIGNED_FREE(ptr) free(ptr)
#endif

#if defined T_AVX512
#define ALIGNMENT 64
#elif defined T_AVX2
#define ALIGNMENT 32
#elif defined T_AVX
#define ALIGNMENT 16
#else
#define ALIGNMENT 8
#define ALIGNMENT 16
#endif

inline uint64_t findNextClosestMultiple(uint64_t number) {
if constexpr (ALIGNMENT == 0) {
return 0;
}

uint64_t remainder = number % ALIGNMENT;
if (remainder == 0) {
return number;
}

uint64_t nextMultiple = number + (ALIGNMENT - remainder);
return nextMultiple;
}

namespace JsonifierInternal {

template<typename ValueType> class AlignedAllocator {
template<typename ValueType> class AlignedAllocator : public std::pmr::polymorphic_allocator<ValueType> {
public:
using value_type = ValueType;
using pointer = value_type*;
using size_type = uint64_t;
using allocator = std::pmr::polymorphic_allocator<ValueType>;

inline pointer allocate(size_type n) const {
inline pointer allocate(size_type n) {
if (n == 0) {
return nullptr;
}
return static_cast<pointer>(ALIGNED_ALLOC(n * sizeof(ValueType), ALIGNMENT));
return static_cast<ValueType*>(allocator::allocate_bytes(findNextClosestMultiple(n * sizeof(value_type)), ALIGNMENT));
}

inline void deallocate(pointer p, size_type) const {
if (p) {
ALIGNED_FREE(p);
inline void deallocate(pointer ptr, size_type n) {
if (ptr) {
allocator::deallocate_bytes(ptr, findNextClosestMultiple(n * sizeof(value_type)), ALIGNMENT);
}
}

template<typename... Args> inline void construct(pointer p, Args&&... args) const {
template<typename... Args> inline void construct(pointer p, Args&&... args) {
new (p) value_type(std::forward<Args>(args)...);
}

inline void destroy(pointer p) const {
inline void destroy(pointer p) {
p->~value_type();
}
};
Expand All @@ -81,24 +88,24 @@ namespace JsonifierInternal {
using value_type = ValueType;
using pointer = value_type*;
using size_type = uint64_t;
using allocator = const AlignedAllocator<value_type>;
using allocator_traits = const std::allocator_traits<allocator>;
using allocator = AlignedAllocator<value_type>;
using allocator_traits = std::allocator_traits<allocator>;

inline AllocWrapper(){};

inline pointer allocate(size_type count) const {
inline pointer allocate(size_type count) {
return allocator_traits::allocate(*this, count);
}

inline void deallocate(pointer ptr, size_type count) const {
inline void deallocate(pointer ptr, size_type count) {
allocator_traits::deallocate(*this, ptr, count);
}

template<typename... Args> inline void construct(pointer ptr, Args&&... args) const {
template<typename... Args> inline void construct(pointer ptr, Args&&... args) {
allocator_traits::construct(*this, ptr, std::forward<Args>(args)...);
}

inline void destroy(pointer ptr) const {
inline void destroy(pointer ptr) {
allocator_traits::destroy(*this, ptr);
}

Expand Down
24 changes: 13 additions & 11 deletions Include/jsonifier/Base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ namespace JsonifierInternal {

class Serializer;

template<typename T> struct always_false : std::false_type {};
template<typename ValueType> struct always_false : std::false_type {};

template<typename T> constexpr bool always_false_v = always_false<T>::value;
template<typename ValueType> constexpr bool always_false_v = always_false<ValueType>::value;

template<typename T> void printTypeInCompilationError(T&&) noexcept {
static_assert(always_false_v<T>, "Compilation failed because you failed to specialize the Core<> template for the following class:");
template<typename ValueType> void printTypeInCompilationError(ValueType&&) noexcept {
static_assert(always_false_v<ValueType>, "Compilation failed because you failed to specialize the Core<> template for the following class:");
}

template<typename ValueType = void> struct Hash {
Expand Down Expand Up @@ -106,8 +106,10 @@ namespace JsonifierInternal {
};

template<typename ValueType>
concept VectorSubscriptable = requires(ValueType value) {
{ value[std::size_t{}] } -> std::same_as<typename ValueType::value_type&>;
concept VectorSubscriptable = requires(ValueType value, uint64_t index) {
{ value[index] } -> std::same_as<typename std::remove_reference_t<ValueType>::reference>;
} || requires(ValueType value, uint64_t index) {
{ value[index] } -> std::same_as<typename std::remove_reference_t<ValueType>::const_reference>;
};

template<typename ValueType>
Expand Down Expand Up @@ -228,12 +230,12 @@ namespace JsonifierInternal {
};
}

template<std::size_t... Is> struct seq {};
template<std::size_t Count, std::size_t... Is> struct gen_seq : gen_seq<Count - 1, Count - 1, Is...> {};
template<std::size_t... Is> struct gen_seq<0, Is...> : seq<Is...> {};
template<std::size_t... Is> struct Sequence {};
template<std::size_t Count, std::size_t... Is> struct GenSeq : GenSeq<Count - 1, Count - 1, Is...> {};
template<std::size_t... Is> struct GenSeq<0, Is...> : Sequence<Is...> {};

template<std::size_t N1, std::size_t... I1, std::size_t N2, std::size_t... I2>
constexpr std::array<const char, N1 + N2 - 1> concat(const char (&a1)[N1], const char (&a2)[N2], seq<I1...>, seq<I2...>) {
constexpr std::array<const char, N1 + N2 - 1> concat(const char (&a1)[N1], const char (&a2)[N2], Sequence<I1...>, Sequence<I2...>) {
return { { a1[I1]..., a2[I2]... } };
}

Expand Down Expand Up @@ -267,7 +269,7 @@ namespace JsonifierInternal {

template<std::size_t n, typename Func> constexpr auto forEach(Func&& f) {
return indexer<n>()([&](auto&&... i) {
(std::forward<Func>(f)(i), ...);
(std::forward<RefUnwrap<Func>>(f)(i), ...);
});
}

Expand Down
Loading

0 comments on commit f835921

Please sign in to comment.