Skip to content

Commit cd0bc54

Browse files
committed
++ cache row span
1 parent 290840b commit cd0bc54

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

storage/cacheRowSpan.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ CacheRowSpan::CacheRowSpan(FlowRecord** begin, size_t count) noexcept
3737

3838
std::optional<size_t> CacheRowSpan::find_by_hash(uint64_t hash) const noexcept
3939
{
40-
for (size_t i = 0; i < m_count; ++i) {
41-
if (m_begin[i]->belongs(hash)) {
42-
return i;
43-
}
40+
auto it = std::find_if(m_begin, m_begin + m_count, [&](const FlowRecord* flow) {
41+
return flow->belongs(hash);
42+
});
43+
if (it == m_begin + m_count) {
44+
return std::nullopt;
4445
}
45-
return std::nullopt;
46+
return it - m_begin;
4647
}
4748

4849
void CacheRowSpan::advance_flow_to(size_t from, size_t to) noexcept
@@ -71,17 +72,6 @@ std::optional<size_t> CacheRowSpan::find_empty() const noexcept
7172
}
7273

7374
#ifdef WITH_CTT
74-
std::optional<size_t> CacheRowSpan::find_if_export_timeout_expired(const timeval& now) const noexcept
75-
{
76-
auto it = std::find_if(m_begin, m_begin + m_count, [&now](const FlowRecord* flow) {
77-
return flow->is_waiting_for_export && now > flow->export_time;
78-
});
79-
if (it == m_begin + m_count) {
80-
return std::nullopt;
81-
}
82-
return it - m_begin;
83-
}
84-
8575
size_t CacheRowSpan::find_victim(const timeval& now) const noexcept
8676
{
8777
const FlowRecord** victim = const_cast<const FlowRecord**>(m_begin) + m_count - 1;
@@ -96,7 +86,6 @@ size_t CacheRowSpan::find_victim(const timeval& now) const noexcept
9686
}
9787
return it - m_begin;
9888
}
99-
10089
#endif /* WITH_CTT */
10190

10291
} // ipxp

storage/cacheRowSpan.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,11 @@ class CacheRowSpan {
6767
std::optional<size_t> find_empty() const noexcept;
6868
#ifdef WITH_CTT
6969
/**
70-
* \brief Find a flow record with an export timeout that has expired.
70+
* \brief Find a flow record to be evicted.
7171
* \param now Current time.
72-
* \return Index of the flow record with an expired export timeout if found, std::nullopt otherwise.
72+
* \return Index of flow from ctt which has delayed export timeout expired if found,
73+
* last record which is not in ctt, or last record otherwise
7374
*/
74-
std::optional<size_t> find_if_export_timeout_expired(const timeval& now) const noexcept;
75-
7675
size_t find_victim(const timeval& now) const noexcept;
7776
#endif /* WITH_CTT */
7877
private:

0 commit comments

Comments
 (0)