mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd::json::tuple: Optimize at() runtime reference template approach.
This commit is contained in:
parent
a82b325341
commit
3412f3e6e3
1 changed files with 24 additions and 48 deletions
|
@ -97,8 +97,8 @@ at(tuple &t,
|
|||
function&& f)
|
||||
{
|
||||
if(indexof<tuple>(name) == i)
|
||||
f(val<i>(t));
|
||||
else
|
||||
return f(val<i>(t));
|
||||
|
||||
at<tuple, function, i + 1>(t, name, std::forward<function>(f));
|
||||
}
|
||||
|
||||
|
@ -121,8 +121,8 @@ at(const tuple &t,
|
|||
function&& f)
|
||||
{
|
||||
if(indexof<tuple>(name) == i)
|
||||
f(val<i>(t));
|
||||
else
|
||||
return f(val<i>(t));
|
||||
|
||||
at<tuple, function, i + 1>(t, name, std::forward<function>(f));
|
||||
}
|
||||
|
||||
|
@ -133,28 +133,16 @@ at(const tuple &t,
|
|||
const string_view &name)
|
||||
{
|
||||
const R *ret;
|
||||
const auto closure
|
||||
{
|
||||
[&name, &ret](const auto &key, const auto &val) noexcept
|
||||
at(t, name, [&ret]
|
||||
(auto&& val)
|
||||
noexcept
|
||||
{
|
||||
//XXX is_pointer_interconvertible_base_of? (C++20)
|
||||
if constexpr(std::is_assignable<R, decltype(val)>())
|
||||
{
|
||||
if(key == name)
|
||||
{
|
||||
ret = std::addressof(val);
|
||||
return false;
|
||||
}
|
||||
else return true;
|
||||
}
|
||||
else return true;
|
||||
}
|
||||
};
|
||||
|
||||
if(unlikely(until(t, closure)))
|
||||
throw not_found
|
||||
{
|
||||
"%s", name
|
||||
};
|
||||
else
|
||||
assert(false);
|
||||
});
|
||||
|
||||
return *ret;
|
||||
}
|
||||
|
@ -166,28 +154,16 @@ at(tuple &t,
|
|||
const string_view &name)
|
||||
{
|
||||
R *ret;
|
||||
const auto closure
|
||||
{
|
||||
[&name, &ret](const auto &key, auto &val) noexcept
|
||||
at(t, name, [&ret]
|
||||
(auto &val)
|
||||
noexcept
|
||||
{
|
||||
//XXX is_pointer_interconvertible_base_of? (C++20)
|
||||
if constexpr(std::is_assignable<R, decltype(val)>())
|
||||
{
|
||||
if(key == name)
|
||||
{
|
||||
ret = std::addressof(val);
|
||||
return false;
|
||||
}
|
||||
else return true;
|
||||
}
|
||||
else return true;
|
||||
}
|
||||
};
|
||||
|
||||
if(unlikely(until(t, closure)))
|
||||
throw not_found
|
||||
{
|
||||
"%s", name
|
||||
};
|
||||
else
|
||||
assert(false);
|
||||
});
|
||||
|
||||
return *ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue