Skip to content

Commit

Permalink
Fix array elements in the runtime to be passed by reference
Browse files Browse the repository at this point in the history
  • Loading branch information
mikir committed Aug 22, 2024
1 parent 8768326 commit da999e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
11 changes: 6 additions & 5 deletions compiler/extensions/cpp/runtime/src/zserio/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ void checkOffset(const OWNER_TYPE&, size_t, size_t)
// call the initContext method properly on packed array traits
template <typename PACKED_ARRAY_TRAITS, typename OWNER_TYPE, typename PACKING_CONTEXT,
typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value, int>::type = 0>
void packedArrayTraitsInitContext(
const OWNER_TYPE& owner, PACKING_CONTEXT& context, typename PACKED_ARRAY_TRAITS::ElementType element)
void packedArrayTraitsInitContext(const OWNER_TYPE& owner, PACKING_CONTEXT& context,
const typename PACKED_ARRAY_TRAITS::ElementType& element)
{
PACKED_ARRAY_TRAITS::initContext(owner, context, element);
}

template <typename PACKED_ARRAY_TRAITS, typename OWNER_TYPE, typename PACKING_CONTEXT,
typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value, int>::type = 0>
void packedArrayTraitsInitContext(
const OWNER_TYPE&, PACKING_CONTEXT& context, typename PACKED_ARRAY_TRAITS::ElementType element)
const OWNER_TYPE&, PACKING_CONTEXT& context, const typename PACKED_ARRAY_TRAITS::ElementType& element)
{
PACKED_ARRAY_TRAITS::initContext(context, element);
}
Expand Down Expand Up @@ -180,7 +180,8 @@ template <typename ARRAY_TRAITS, typename OWNER_TYPE,
typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value &&
std::is_scalar<typename ARRAY_TRAITS::ElementType>::value,
int>::type = 0>
size_t arrayTraitsInitializeOffsets(OWNER_TYPE&, size_t bitPosition, typename ARRAY_TRAITS::ElementType element)
size_t arrayTraitsInitializeOffsets(
OWNER_TYPE&, size_t bitPosition, const typename ARRAY_TRAITS::ElementType& element)
{
return ARRAY_TRAITS::initializeOffsets(bitPosition, element);
}
Expand Down Expand Up @@ -209,7 +210,7 @@ template <typename PACKED_ARRAY_TRAITS, typename OWNER_TYPE, typename PACKING_CO
std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
int>::type = 0>
size_t packedArrayTraitsInitializeOffsets(OWNER_TYPE&, PACKING_CONTEXT& context, size_t bitPosition,
typename PACKED_ARRAY_TRAITS::ElementType element)
const typename PACKED_ARRAY_TRAITS::ElementType& element)
{
return PACKED_ARRAY_TRAITS::initializeOffsets(context, bitPosition, element);
}
Expand Down
19 changes: 10 additions & 9 deletions compiler/extensions/cpp/runtime/src/zserio/DeltaContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class DeltaContext
* \param element Current element.
*/
template <typename ARRAY_TRAITS, typename OWNER_TYPE>
void init(const OWNER_TYPE& owner, typename ARRAY_TRAITS::ElementType element)
void init(const OWNER_TYPE& owner, const typename ARRAY_TRAITS::ElementType& element)
{
m_numElements++;
m_unpackedBitSize += bitSizeOfUnpacked<ARRAY_TRAITS>(owner, element);
Expand Down Expand Up @@ -124,7 +124,7 @@ class DeltaContext
* \return Length of the packed element stored in the bit stream in bits.
*/
template <typename ARRAY_TRAITS, typename OWNER_TYPE>
size_t bitSizeOf(const OWNER_TYPE& owner, typename ARRAY_TRAITS::ElementType element)
size_t bitSizeOf(const OWNER_TYPE& owner, const typename ARRAY_TRAITS::ElementType& element)
{
if (!isFlagSet(PROCESSING_STARTED_FLAG))
{
Expand Down Expand Up @@ -188,7 +188,7 @@ class DeltaContext
* \param element Value of the current element.
*/
template <typename ARRAY_TRAITS, typename OWNER_TYPE>
void write(const OWNER_TYPE& owner, BitStreamWriter& out, typename ARRAY_TRAITS::ElementType element)
void write(const OWNER_TYPE& owner, BitStreamWriter& out, const typename ARRAY_TRAITS::ElementType& element)
{
if (!isFlagSet(PROCESSING_STARTED_FLAG))
{
Expand Down Expand Up @@ -222,7 +222,7 @@ class DeltaContext
* \param element Current element.
*/
template <typename ARRAY_TRAITS>
void init(typename ARRAY_TRAITS::ElementType element)
void init(const typename ARRAY_TRAITS::ElementType& element)
{
init<ARRAY_TRAITS>(DummyOwner(), element);
}
Expand All @@ -235,7 +235,7 @@ class DeltaContext
* \return Length of the packed element stored in the bit stream in bits.
*/
template <typename ARRAY_TRAITS>
size_t bitSizeOf(typename ARRAY_TRAITS::ElementType element)
size_t bitSizeOf(const typename ARRAY_TRAITS::ElementType& element)
{
return bitSizeOf<ARRAY_TRAITS>(DummyOwner(), element);
}
Expand All @@ -260,7 +260,7 @@ class DeltaContext
* \param element Value of the current element.
*/
template <typename ARRAY_TRAITS>
void write(BitStreamWriter& out, typename ARRAY_TRAITS::ElementType element)
void write(BitStreamWriter& out, const typename ARRAY_TRAITS::ElementType& element)
{
write<ARRAY_TRAITS>(DummyOwner(), out, element);
}
Expand Down Expand Up @@ -299,14 +299,14 @@ class DeltaContext
template <typename ARRAY_TRAITS,
typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value, int>::type = 0>
static size_t bitSizeOfUnpacked(
const typename ARRAY_TRAITS::OwnerType& owner, typename ARRAY_TRAITS::ElementType element)
const typename ARRAY_TRAITS::OwnerType& owner, const typename ARRAY_TRAITS::ElementType& element)
{
return ARRAY_TRAITS::bitSizeOf(owner, element);
}

template <typename ARRAY_TRAITS,
typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value, int>::type = 0>
static size_t bitSizeOfUnpacked(const DummyOwner&, typename ARRAY_TRAITS::ElementType element)
static size_t bitSizeOfUnpacked(const DummyOwner&, const typename ARRAY_TRAITS::ElementType& element)
{
return ARRAY_TRAITS::bitSizeOf(element);
}
Expand Down Expand Up @@ -364,7 +364,8 @@ class DeltaContext

template <typename ARRAY_TRAITS,
typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value, int>::type = 0>
void writeUnpacked(const DummyOwner&, BitStreamWriter& out, typename ARRAY_TRAITS::ElementType element)
void writeUnpacked(
const DummyOwner&, BitStreamWriter& out, const typename ARRAY_TRAITS::ElementType& element)
{
m_previousElement = static_cast<uint64_t>(element);
ARRAY_TRAITS::write(out, element);
Expand Down

0 comments on commit da999e5

Please sign in to comment.