Skip to content

Commit 40cc76f

Browse files
committed
++ cache
1 parent 10f3094 commit 40cc76f

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

storage/cache.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ NHTFlowCache::find_row(const std::variant<FlowKeyv4, FlowKeyv6>& key, const std:
220220
const size_t first_flow_in_row = hash_value & m_line_mask;
221221
const CacheRowSpan row(&m_flow_table[first_flow_in_row], m_line_size);
222222
if (const std::optional<size_t> flow_index = row.find_by_hash(hash_value, vlan_id); flow_index.has_value()) {
223-
return {row, first_flow_in_row + flow_index.value(), hash_value};
223+
return {row, first_flow_in_row + *flow_index, hash_value};
224224
}
225225
return {row, std::nullopt, hash_value};
226226
}
@@ -232,15 +232,15 @@ NHTFlowCache::find_flow_index(const std::variant<FlowKeyv4, FlowKeyv6>& key,
232232

233233
const auto [direct_row, direct_flow_index, direct_hash_value] = find_row(key, vlan_id);
234234
if (direct_flow_index.has_value()) {
235-
return {direct_row, std::make_pair(direct_flow_index.value(), true)};
235+
return {direct_row, std::make_pair(*direct_flow_index, true)};
236236
}
237237
if (m_split_biflow) {
238238
return {direct_row, direct_hash_value};
239239
}
240240

241241
const auto [reversed_row, reversed_flow_index, reversed_hash_value] = find_row(key_reversed, vlan_id);
242242
if (reversed_flow_index.has_value()) {
243-
return {reversed_row, std::make_pair(reversed_flow_index.value(), false)};
243+
return {reversed_row, std::make_pair(*reversed_flow_index, false)};
244244
}
245245

246246
return {direct_row, direct_hash_value};
@@ -528,10 +528,10 @@ int NHTFlowCache::put_pkt(Packet& packet)
528528
auto [row, flow_identification] =
529529
find_flow_index(direct_key, reversed_key, packet.vlan_id);
530530

531-
if (std::holds_alternative<size_t>(flow_identification)) {
532-
const size_t hash_value = std::get<size_t>(flow_identification);
533-
const size_t empty_place = get_empty_place(row, packet.ts) + (hash_value & m_line_mask);
534-
create_record(packet, empty_place, hash_value);
531+
if (const size_t* hash_value = std::get_if<size_t>(&flow_identification)) {
532+
//const size_t hash_value = std::visit([](const size_t hash_value){ return hash_value;},flow_identification);
533+
const size_t empty_place = get_empty_place(row, packet.ts) + (*hash_value & m_line_mask);
534+
create_record(packet, empty_place, *hash_value);
535535
export_expired(packet.ts);
536536
return 0;
537537
}

storage/cacheRowSpan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ CacheRowSpan::CacheRowSpan(FlowRecord** begin, size_t count) noexcept
3535
{
3636
}
3737

38-
std::optional<size_t> CacheRowSpan::find_by_hash(uint64_t hash, std::optional<uint16_t> vlan_id) const noexcept
38+
std::optional<size_t> CacheRowSpan::find_by_hash(uint64_t hash, const std::optional<uint16_t>& vlan_id) const noexcept
3939
{
4040
FlowRecord** it = nullptr;
4141
if (!vlan_id.has_value()) {

storage/cacheRowSpan.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CacheRowSpan {
4646
* \param hash Hash value to search for.
4747
* \return Index of the flow record relative to row begin if found, std::nullopt otherwise.
4848
*/
49-
std::optional<size_t> find_by_hash(uint64_t hash, std::optional<uint16_t> vlan_id = std::nullopt) const noexcept;
49+
std::optional<size_t> find_by_hash(uint64_t hash, const std::optional<uint16_t>& vlan_id = std::nullopt) const noexcept;
5050
/**
5151
* \brief Move a flow record to the beginning of the row.
5252
* \param flow_index Index of the flow record to move.

0 commit comments

Comments
 (0)