Skip to content
Closed
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
78 changes: 49 additions & 29 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,18 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Cache apt packages
uses: actions/cache@v3
with:
path: /var/cache/apt/archives
key: ${{ runner.os }}-apt-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-apt-

- name: Install dependencies (Linux)
if: runner.os == 'Linux'
- name: Install dependencies
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y cmake ninja-build build-essential
if [[ "${{ matrix.c_compiler }}" == "clang" ]]; then
sudo apt-get install -y clang lld
if [[ "${{ runner.os }}" == "Linux" ]]; then
sudo apt-get update
sudo apt-get install -y cmake ninja-build build-essential
if [[ "${{ matrix.c_compiler }}" == "clang" ]]; then
sudo apt-get install -y clang lld
fi
elif [[ "${{ runner.os }}" == "Windows" ]]; then
choco install cmake --installargs '"ADD_CMAKE_TO_PATH=System"' -y
choco install ninja -y
fi

- name: Cache CMake files
Expand All @@ -63,24 +60,37 @@ jobs:
id: strings
shell: bash
run: |
echo "build-output-dir=${GITHUB_WORKSPACE}/build" >> "$GITHUB_OUTPUT"
if [[ "${{ runner.os }}" == "Linux" ]]; then
echo "build-output-dir=${GITHUB_WORKSPACE}/build" >> "$GITHUB_OUTPUT"
elif [[ "${{ runner.os }}" == "Windows" ]]; then
echo "build-output-dir=${GITHUB_WORKSPACE}\build" >> "$GITHUB_OUTPUT"
fi

- name: Create build directory
run: cmake -E make_directory ${{ steps.strings.outputs.build-output-dir }}

- name: Configure CMake (Linux)
if: runner.os == 'Linux'
- name: Configure CMake
shell: bash
run: |
cmake -B ${{ steps.strings.outputs.build-output-dir }} \
-DCMAKE_CXX_STANDARD=20 \
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} \
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }} \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-G Ninja \
-S ${{ github.workspace }}
if [[ "${{ runner.os }}" == "Linux" ]]; then
cmake -B "${{ steps.strings.outputs.build-output-dir }}" \
-DCMAKE_CXX_STANDARD=20 \
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} \
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }} \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-G Ninja \
-S ${{ github.workspace }}
elif [[ "${{ runner.os }}" == "Windows" ]]; then
cmake -B "${{ steps.strings.outputs.build-output-dir }}" \
-DCMAKE_CXX_STANDARD=20 \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-G Ninja \
-A x64 \
-S ${{ github.workspace }}
fi

- name: Cache build
uses: actions/cache@v3
uses: actions/cache@v31
with:
path: ${{ github.workspace }}/build
key: ${{ runner.os }}-build-${{ hashFiles('**/*.cpp', '**/*.hpp', '**/*.h') }}
Expand All @@ -96,14 +106,24 @@ jobs:

- name: Run tests
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ./tests
run: |
if [[ "${{ runner.os }}" == "Windows" ]]; then
.\tests.exe
else
./tests
fi

- name: Run benchmarks
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ./measure --benchmark_format=console --benchmark_out=benchmark_results.json
run: |
if [[ "${{ runner.os }}" == "Windows" ]]; then
.\measure.exe --benchmark_format=console --benchmark_out=benchmark_results.json
else
./measure --benchmark_format=console --benchmark_out=benchmark_results.json
fi

- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: benchmark_results.json
name: benchmark-results
path: benchmark_results.json
6 changes: 2 additions & 4 deletions fastcast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
#define CONSTEXPR
#endif


namespace fastcast {

// Core implementation for pointer types
template <typename To, typename From> CONSTEXPR inline To cast_impl(From *ptr) {
template <typename To, typename From> CONSTEXPR inline To fast_cast_impl(From *ptr) {
using v_table_ptr = const uintptr_t *;
if constexpr (std::is_same_v<std::remove_cv_t<From>,
std::remove_pointer_t<To>>) {
Expand Down Expand Up @@ -76,7 +74,7 @@ constexpr inline To fast_cast(From *ptr) {
using ToNonPtr = std::remove_pointer_t<To>;
using ToPtr =
std::conditional_t<std::is_const_v<From>, const ToNonPtr *, ToNonPtr *>;
return cast_impl<ToPtr>(ptr);
return fast_cast_impl<ToPtr>(ptr);
}

// Reference overload
Expand Down
Loading