Skip to content

Commit

Permalink
Remove static member function mutator::locate
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Mar 22, 2024
1 parent b385305 commit 03e0b8b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 41 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Procedures for each standard are provided by the following R7RS-style libraries:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make package
sudo apt install build/meevax_0.5.150_amd64.deb
sudo apt install build/meevax_0.5.151_amd64.deb
```

or
Expand Down Expand Up @@ -123,9 +123,9 @@ sudo rm -rf /usr/local/share/meevax

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.5.150.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.151.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.150_amd64.deb`
| `package` | Generate debian package `meevax_0.5.151_amd64.deb`
| `install` | Copy files into `/usr/local` directly

## Usage
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.150
0.5.151
37 changes: 6 additions & 31 deletions include/meevax/memory/collector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ inline namespace memory
protected:
top const* object = nullptr;

constexpr mutator() = default;
mutator() = default;

explicit mutator(top const* object) noexcept
: object { object }
Expand All @@ -173,41 +173,18 @@ inline namespace memory

~mutator() noexcept
{
if (object)
{
mutators.erase(this);
}
mutators.erase(this);
}

auto reset(top const* after = nullptr) noexcept -> void
{
if (auto before = std::exchange(object, after); not before and after)
if (object = after; after)
{
mutators.insert(this);
}
else if (before and not after)
{
mutators.erase(this);
}
}

static auto locate(void const* const data) noexcept -> top const*
{
if (not data)
{
return nullptr;
}
else if (cache->contains(data))
{
return cache;
}
else if (auto iter = objects.lower_bound(reinterpret_cast<top const*>(data)); iter != objects.begin() and (*--iter)->contains(data))
{
return *iter;
}
else
{
return nullptr;
mutators.erase(this);
}
}
};
Expand All @@ -222,8 +199,6 @@ inline namespace memory
using pointer_set = integer_set<T const*, 15, 16, 16>;

private:
static inline top * cache = nullptr;

static inline pointer_set<top> objects {};

static inline pointer_set<mutator> mutators {};
Expand All @@ -247,7 +222,7 @@ inline namespace memory

auto operator =(collector const&) -> collector & = delete;

template <typename T, typename Allocator = default_allocator<void>, typename... Ts>
template <typename T, typename... Ts>
static auto make(Ts&&... xs)
{
static_assert(std::is_base_of_v<top, T>);
Expand All @@ -259,7 +234,7 @@ inline namespace memory

if (auto data = new T(std::forward<decltype(xs)>(xs)...); data)
{
objects.insert(cache = data);
objects.insert(data);

return data;
}
Expand Down
8 changes: 4 additions & 4 deletions include/meevax/memory/gc_pointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ inline namespace memory

gc_pointer(base_pointer const& p)
: base_pointer { p }
, collector::mutator { locate(base_pointer::get()) }
, collector::mutator { base_pointer::get() }
{}

gc_pointer(std::nullptr_t = nullptr)
{}

gc_pointer(Top * top) // TODO Top const*
: base_pointer { top }
, collector::mutator { locate(base_pointer::get()) }
, collector::mutator { base_pointer::get() }
{}

template <typename T, typename = std::enable_if_t<(std::is_same_v<T, Ts> or ... or std::is_same_v<T, double>)>>
Expand Down Expand Up @@ -85,7 +85,7 @@ inline namespace memory
auto reset(base_pointer const& p) -> void
{
base_pointer::reset(p);
collector::mutator::reset(locate(base_pointer::get()));
collector::mutator::reset(base_pointer::get());
}

auto reset(std::nullptr_t = nullptr) -> void
Expand All @@ -99,7 +99,7 @@ inline namespace memory
{
if constexpr (std::is_class_v<Bound>)
{
return collector::make<collector::binder<Top, Bound, std::allocator_traits<Allocator>>, Allocator>(std::forward<decltype(xs)>(xs)...);
return collector::make<collector::binder<Top, Bound, std::allocator_traits<Allocator>>>(std::forward<decltype(xs)>(xs)...);
}
else
{
Expand Down
6 changes: 4 additions & 2 deletions include/meevax/memory/integer_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ inline namespace memory

auto erase(T value) noexcept
{
auto [i, j] = split(value);
data[i]->erase(j);
if (auto [i, j] = split(value); data[i])
{
data[i]->erase(j);
}
}

auto contains(T value) noexcept -> bool
Expand Down

0 comments on commit 03e0b8b

Please sign in to comment.