Speed up the reflection process (#537)

This commit is contained in:
Dr. Patrick Urbanke (劉自成)
2025-11-02 22:01:15 +01:00
committed by GitHub
parent 49ac063866
commit e47dfbeb1f
6 changed files with 4432 additions and 2804 deletions
+3
View File
@@ -5,6 +5,9 @@ on: [ push, pull_request ]
jobs:
linux:
name: "${{ github.job }} (Conan)"
concurrency:
group: "linux-${{ github.ref }}-${{ github.job }}-conan"
cancel-in-progress: true
runs-on: ubuntu-24.04
steps:
- name: Checkout
+3
View File
@@ -45,6 +45,9 @@ jobs:
compiler-version: 17
cxx: 23
name: "${{ github.job }} (${{ matrix.format }}-C++${{ matrix.cxx }}-${{ matrix.compiler }}-${{ matrix.compiler-version }})"
concurrency:
group: "linux-${{ github.ref }}-${{ github.job }}-${{ matrix.format }}-C++${{ matrix.cxx }}-${{ matrix.compiler }}-${{ matrix.compiler-version }}"
cancel-in-progress: true
runs-on: ubuntu-24.04
steps:
- name: Checkout
+3
View File
@@ -13,6 +13,9 @@ jobs:
os: ["macos-latest", "macos-13"]
format: ["tests", "benchmarks"]
name: "${{ matrix.os }} (${{ matrix.format }})"
concurrency:
group: "macos-${{ github.ref }}-${{ github.job }}-${{ matrix.os }}-${{ matrix.format }}"
cancel-in-progress: true
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
+3
View File
@@ -12,6 +12,9 @@ jobs:
matrix:
format: ["JSON", "AVRO", "CAPNPROTO", "CBOR", "FLEXBUFFERS", "MSGPACK", "PARQUET", "TOML", "UBJSON", "XML", "YAML", "benchmarks"]
name: "windows-msvc (${{ matrix.format }})"
concurrency:
group: "windows-${{ github.ref }}-${{ github.job }}-${{ matrix.format }}"
cancel-in-progress: true
runs-on: windows-latest
steps:
- name: Checkout
File diff suppressed because it is too large Load Diff
+53
View File
@@ -0,0 +1,53 @@
"""
Creates the boilerplate code in rfl/internal/bind_to_tuple.hpp
"""
def _make_macro(num: int) -> str:
fields = ", ".join((f"f{i+1}" for i in range(num)))
return f"RFL_INTERNAL_TUPLE_VIEW_IF_YOU_SEE_AN_ERROR_REFER_TO_DOCUMENTATION_ON_C_ARRAYS({num}, {fields});"
def _generate_macros(minimum: int, maximum: int, depth: int = 0) -> str:
if maximum <= minimum:
return _make_macro(minimum)
mid = int((minimum + maximum + 1) / 2)
leg1 = _generate_macros(minimum, mid - 1, depth + 1)
leg2 = _generate_macros(mid, maximum, depth + 1)
return (
"if constexpr(_num_fields < "
+ str(mid)
+ ") {\n"
+ " " * (depth + 1)
+ leg1
+ "\n"
+ " " * depth
+ "} else {\n"
+ " " * (depth + 1)
+ leg2
+ "\n"
+ " " * depth
+ "}"
)
def _generate_bind_to_tuple_impl(maximum: int) -> str:
macros = _generate_macros(1, maximum)
return (
"""
template<class T, std::size_t _num_fields>
auto bind_to_tuple_impl(auto& _t) {
if constexpr(_num_fields == 0) {
return rfl::make_tuple();
} else {
"""
+ macros
+ """
}
}
"""
)
with open("generated_code_bind_to_tuple.cpp", "w", encoding="utf-8") as codefile:
codefile.write(_generate_bind_to_tuple_impl(256))