mirror of
https://github.com/matrix-construct/construct
synced 2024-09-27 11:18:51 +02:00
ircd::allocator: Deinline non-template assets.
This commit is contained in:
parent
e2f77e9873
commit
c6bd9d63e8
3 changed files with 67 additions and 57 deletions
|
@ -403,60 +403,3 @@ struct ircd::allocator::node<T>::allocator
|
|||
return &a == &b;
|
||||
}
|
||||
};
|
||||
|
||||
inline void
|
||||
ircd::allocator::state::deallocate(const uint &pos,
|
||||
const size_type &n)
|
||||
{
|
||||
for(size_t i(0); i < n; ++i)
|
||||
{
|
||||
assert(test(pos + i));
|
||||
btc(pos + i);
|
||||
}
|
||||
|
||||
last = pos;
|
||||
}
|
||||
|
||||
inline uint
|
||||
ircd::allocator::state::allocate(const size_type &n,
|
||||
const uint &hint)
|
||||
{
|
||||
const auto next(this->next(n));
|
||||
if(unlikely(next >= size)) // No block of n was found anywhere (next is past-the-end)
|
||||
throw std::bad_alloc();
|
||||
|
||||
for(size_t i(0); i < n; ++i)
|
||||
{
|
||||
assert(!test(next + i));
|
||||
bts(next + i);
|
||||
}
|
||||
|
||||
last = next + n;
|
||||
return next;
|
||||
}
|
||||
|
||||
inline uint
|
||||
ircd::allocator::state::next(const size_t &n)
|
||||
const
|
||||
{
|
||||
uint ret(last), rem(n);
|
||||
for(; ret < size && rem; ++ret)
|
||||
if(test(ret))
|
||||
rem = n;
|
||||
else
|
||||
--rem;
|
||||
|
||||
if(likely(!rem))
|
||||
return ret - n;
|
||||
|
||||
for(ret = 0, rem = n; ret < last && rem; ++ret)
|
||||
if(test(ret))
|
||||
rem = n;
|
||||
else
|
||||
--rem;
|
||||
|
||||
if(unlikely(rem)) // The allocator should throw std::bad_alloc if !rem
|
||||
return size;
|
||||
|
||||
return ret - n;
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ libircd_la_LIBADD = \
|
|||
# systems.
|
||||
libircd_la_SOURCES = \
|
||||
exception.cc \
|
||||
allocator.cc \
|
||||
lexical.cc \
|
||||
tokens.cc \
|
||||
json.cc \
|
||||
|
|
66
ircd/allocator.cc
Normal file
66
ircd/allocator.cc
Normal file
|
@ -0,0 +1,66 @@
|
|||
// Matrix Construct
|
||||
//
|
||||
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
||||
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice is present in all copies. The
|
||||
// full license for this software is available in the LICENSE file.
|
||||
|
||||
void
|
||||
ircd::allocator::state::deallocate(const uint &pos,
|
||||
const size_type &n)
|
||||
{
|
||||
for(size_t i(0); i < n; ++i)
|
||||
{
|
||||
assert(test(pos + i));
|
||||
btc(pos + i);
|
||||
}
|
||||
|
||||
last = pos;
|
||||
}
|
||||
|
||||
uint
|
||||
ircd::allocator::state::allocate(const size_type &n,
|
||||
const uint &hint)
|
||||
{
|
||||
const auto next(this->next(n));
|
||||
if(unlikely(next >= size)) // No block of n was found anywhere (next is past-the-end)
|
||||
throw std::bad_alloc();
|
||||
|
||||
for(size_t i(0); i < n; ++i)
|
||||
{
|
||||
assert(!test(next + i));
|
||||
bts(next + i);
|
||||
}
|
||||
|
||||
last = next + n;
|
||||
return next;
|
||||
}
|
||||
|
||||
uint
|
||||
ircd::allocator::state::next(const size_t &n)
|
||||
const
|
||||
{
|
||||
uint ret(last), rem(n);
|
||||
for(; ret < size && rem; ++ret)
|
||||
if(test(ret))
|
||||
rem = n;
|
||||
else
|
||||
--rem;
|
||||
|
||||
if(likely(!rem))
|
||||
return ret - n;
|
||||
|
||||
for(ret = 0, rem = n; ret < last && rem; ++ret)
|
||||
if(test(ret))
|
||||
rem = n;
|
||||
else
|
||||
--rem;
|
||||
|
||||
if(unlikely(rem)) // The allocator should throw std::bad_alloc if !rem
|
||||
return size;
|
||||
|
||||
return ret - n;
|
||||
}
|
Loading…
Reference in a new issue