Skip to content

Commit 58cc36b

Browse files
falucocodebot
authored andcommitted
OFH: Optimize deserializer span read
1 parent 423464b commit 58cc36b

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

lib/ofh/ethernet/vlan_ethernet_frame_builder_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ void vlan_frame_builder_impl::build_vlan_frame(span<uint8_t> buffer, const vlan_
2525
ofh::network_order_binary_serializer serializer(buffer.data());
2626

2727
// Write destination MAC address (6 Bytes).
28-
serializer.write(span<const uint8_t>(eth_params.mac_dst_address));
28+
serializer.write(eth_params.mac_dst_address);
2929

3030
// Write source MAC address (6 Bytes).
31-
serializer.write(span<const uint8_t>(eth_params.mac_src_address));
31+
serializer.write(eth_params.mac_src_address);
3232

3333
// Write VLAN TPID (2 Bytes).
3434
serializer.write(VLAN_TPID);

lib/ofh/ethernet/vlan_ethernet_frame_decoder_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ span<const uint8_t> vlan_frame_decoder_impl::decode(span<const uint8_t> frame, v
3030

3131
ofh::network_order_binary_deserializer deserializer(frame);
3232

33-
deserializer.read(span<uint8_t>(eth_params.mac_dst_address));
34-
deserializer.read(span<uint8_t>(eth_params.mac_src_address));
33+
deserializer.read(eth_params.mac_dst_address);
34+
deserializer.read(eth_params.mac_src_address);
3535

3636
// VLAN parameters are stripped by the NIC.
3737

lib/ofh/serdes/ofh_uplane_message_decoder_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static bool decode_prbs_no_ud_comp_param_field(span<compressed_prb>
217217
// No need to read the udCompParam field.
218218
prb.set_compression_param(0);
219219

220-
deserializer.read<uint8_t>(prb.get_byte_buffer().first(nof_bytes));
220+
deserializer.read(prb.get_byte_buffer().first(nof_bytes));
221221
prb.set_stored_size(nof_bytes);
222222
}
223223

@@ -254,7 +254,7 @@ static bool decode_prbs_with_ud_comp_param_field(span<compressed_prb>
254254
for (auto& prb : comp_prb) {
255255
prb.set_compression_param(deserializer.read<uint8_t>());
256256

257-
deserializer.read<uint8_t>(prb.get_byte_buffer().first(nof_bytes));
257+
deserializer.read(prb.get_byte_buffer().first(nof_bytes));
258258
prb.set_stored_size(nof_bytes);
259259
}
260260

lib/ofh/support/network_order_binary_deserializer.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,21 @@ class network_order_binary_deserializer
5151
/// Deserializes a fixed amount of elements given by the size of the input span and advances the position by sizeof(T)
5252
/// bytes for each element.
5353
template <typename T>
54-
void read(span<T> data)
54+
void read(span<T> s)
5555
{
56-
for (auto& element : data) {
56+
for (auto& element : s) {
5757
element = read<T>();
5858
}
5959
}
6060

61+
/// Deserializes a fixed amount of bytes given by the size of the input span and advances the position by the span
62+
/// size.
63+
void read(span<uint8_t> s)
64+
{
65+
std::memcpy(s.data(), ptr, s.size() * sizeof(uint8_t));
66+
advance(s.size() * sizeof(uint8_t));
67+
}
68+
6169
/// Advances the offset by the given amount.
6270
void advance(unsigned x)
6371
{

lib/ofh/support/network_order_binary_serializer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class network_order_binary_serializer
6565
/// Serializes the given span of bytes and advances the position by the span size.
6666
void write(span<const uint8_t> s)
6767
{
68-
std::memcpy(ptr, s.data(), s.size());
69-
advance(s.size());
68+
std::memcpy(ptr, s.data(), s.size() * sizeof(uint8_t));
69+
advance(s.size() * sizeof(uint8_t));
7070
}
7171

7272
/// Serializes the given span of bytes and advances the position by the span size.

0 commit comments

Comments
 (0)