mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibIPC: Encode spans of trivial arithmetic types more efficiently
For stuff like Span<u8>, we should obviously grow the message buffer once, and then copy all the bytes in one go.
This commit is contained in:
parent
1c45930767
commit
096eddfd5a
Notes:
github-actions[bot]
2025-12-01 14:14:18 +00:00
Author: https://github.com/awesomekling
Commit: 096eddfd5a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6982
Reviewed-by: https://github.com/gmta ✅
2 changed files with 15 additions and 0 deletions
|
|
@ -125,6 +125,8 @@ class Span : public Detail::Span<T> {
|
||||||
public:
|
public:
|
||||||
using Detail::Span<T>::Span;
|
using Detail::Span<T>::Span;
|
||||||
|
|
||||||
|
using ElementType = T;
|
||||||
|
|
||||||
constexpr Span() = default;
|
constexpr Span() = default;
|
||||||
|
|
||||||
[[nodiscard]] ALWAYS_INLINE constexpr T const* data() const { return this->m_values; }
|
[[nodiscard]] ALWAYS_INLINE constexpr T const* data() const { return this->m_values; }
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,7 @@ template<>
|
||||||
ErrorOr<void> encode(Encoder&, URL::BlobURLEntry::MediaSource const&);
|
ErrorOr<void> encode(Encoder&, URL::BlobURLEntry::MediaSource const&);
|
||||||
|
|
||||||
template<Concepts::Span T>
|
template<Concepts::Span T>
|
||||||
|
requires(!IsArithmetic<typename T::ElementType>)
|
||||||
ErrorOr<void> encode(Encoder& encoder, T const& span)
|
ErrorOr<void> encode(Encoder& encoder, T const& span)
|
||||||
{
|
{
|
||||||
TRY(encoder.encode_size(span.size()));
|
TRY(encoder.encode_size(span.size()));
|
||||||
|
|
@ -149,6 +150,18 @@ ErrorOr<void> encode(Encoder& encoder, T const& span)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<Concepts::Span T>
|
||||||
|
requires(IsArithmetic<typename T::ElementType>)
|
||||||
|
ErrorOr<void> encode(Encoder& encoder, T const& span)
|
||||||
|
{
|
||||||
|
TRY(encoder.encode_size(span.size()));
|
||||||
|
|
||||||
|
VERIFY(!Checked<size_t>::multiplication_would_overflow(span.size(), sizeof(typename T::ElementType)));
|
||||||
|
TRY(encoder.append(reinterpret_cast<u8 const*>(span.data()), span.size() * sizeof(typename T::ElementType)));
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T, size_t N>
|
template<typename T, size_t N>
|
||||||
ErrorOr<void> encode(Encoder& encoder, Array<T, N> const& array)
|
ErrorOr<void> encode(Encoder& encoder, Array<T, N> const& array)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue