0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-11 14:38:57 +02:00

ircd::allocator: Deinline non-template assets.

This commit is contained in:
Jason Volk 2018-05-25 00:15:49 -07:00
parent e2f77e9873
commit c6bd9d63e8
3 changed files with 67 additions and 57 deletions

View file

@ -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;
}

View file

@ -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
View 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;
}