Skip to content

Commit

Permalink
Prove concept usage for static objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jeaye committed Jun 30, 2023
1 parent 0ebf3ad commit 3c0ab47
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <jank/obj-model/tagged/object.hpp>

namespace jank::obj_model::tagged
{
template <typename T>
concept associatively_readable = requires(T * const t)
{
{ t->get(object_ptr{}) } -> std::convertible_to<object_ptr>;
{ t->get(object_ptr{}, object_ptr{}) } -> std::convertible_to<object_ptr>;
};
}
1 change: 1 addition & 0 deletions new-obj-model/include/jank/obj-model/tagged/unerase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace jank::obj_model::tagged
{
/* TODO: Rename to visit. */
template <typename F>
[[gnu::always_inline, gnu::flatten, gnu::hot]]
inline void unerase_type(object *const erased, F &&fn)
Expand Down
10 changes: 7 additions & 3 deletions new-obj-model/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <concepts>

#include <gc/gc.h>
#include <gc/gc_cpp.h>
#include <nanobench.h>
Expand All @@ -8,6 +10,7 @@
#include <jank/obj-model/tagged/unerase.hpp>
#include <jank/obj-model/tagged/map.hpp>
#include <jank/obj-model/tagged/keyword.hpp>
#include <jank/obj-model/tagged/associatively_readable.hpp>

void benchmark_inheritance(ankerl::nanobench::Config const &config)
{
Expand Down Expand Up @@ -62,7 +65,7 @@ void benchmark_inheritance(ankerl::nanobench::Config const &config)
assert(found);
}

void benchmark_bitfield(ankerl::nanobench::Config const &config)
void benchmark_tagged(ankerl::nanobench::Config const &config)
{
using namespace jank::obj_model::tagged;

Expand Down Expand Up @@ -122,13 +125,14 @@ void benchmark_bitfield(ankerl::nanobench::Config const &config)
[&](auto * const typed_map)
{
using T = std::decay_t<decltype(typed_map)>;
if constexpr(std::is_same_v<T, static_map*>)
if constexpr(jank::obj_model::tagged::associatively_readable<T>)
{ res = typed_map->get(erase_type(kw_a)); }
}
);
}
);
assert(res);

}

int main()
Expand All @@ -141,7 +145,7 @@ int main()
config.mWarmup = 10000;

benchmark_inheritance(config);
benchmark_bitfield(config);
benchmark_tagged(config);

ankerl::nanobench::Bench().config(config).run
(
Expand Down

0 comments on commit 3c0ab47

Please sign in to comment.