Skip to content

Commit

Permalink
refactor: minor change in for loops
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Aponte <[email protected]>
  • Loading branch information
federico-sysdig committed May 3, 2024
1 parent f92b666 commit 8d0c4b5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
1 change: 0 additions & 1 deletion userspace/libsinsp/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#pragma once

#include <cstdint>
#include <string>
#include <cstdint>

Expand Down
4 changes: 1 addition & 3 deletions userspace/libsinsp/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,8 @@ std::list<sinsp_filter_factory::filter_fieldclass_info> sinsp_filter_factory::ch
cinfo.desc = fci->m_desc;
cinfo.shortdesc = fci->m_shortdesc;

for(int32_t k = 0; k < fci->m_nfields; k++)
for(auto fld = fci->m_fields; fld != fci->m_fields + fci->m_nfields; ++fld)
{
const filtercheck_field_info* fld = &fci->m_fields[k];

// If a field is only used to organize events,
// we don't want to print it and don't return it here.
if(fld->m_flags & EPF_PRINT_ONLY)
Expand Down
12 changes: 6 additions & 6 deletions userspace/libsinsp/sinsp_filtercheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,6 @@ Json::Value sinsp_filter_check::tojson(sinsp_evt* evt)

int32_t sinsp_filter_check::parse_field_name(std::string_view str, bool alloc_state, bool needed_for_filtering)
{
int32_t j;
int32_t max_fldlen = -1;
uint32_t max_flags = 0;

Expand All @@ -1224,24 +1223,25 @@ int32_t sinsp_filter_check::parse_field_name(std::string_view str, bool alloc_st

m_field_id = 0xffffffff;

for(j = 0; j < m_info.m_nfields; j++)
for(int32_t j = 0; j != m_info.m_nfields; ++j)
{
int32_t fldlen = (int32_t)strlen(m_info.m_fields[j].m_name);
auto& fld = m_info.m_fields[j];
int32_t fldlen = (int32_t)strlen(fld.m_name);
if(fldlen <= max_fldlen)
{
continue;
}

/* Here we are searching for the longest match */
if(str.compare(0, fldlen, m_info.m_fields[j].m_name) == 0)
if(str.compare(0, fldlen, fld.m_name) == 0)
{
/* we found some info about the required field, we save it in this way
* we don't have to loop again through the fields.
*/
m_field_id = j;
m_field = &m_info.m_fields[j];
m_field = &fld;
max_fldlen = fldlen;
max_flags = (m_info.m_fields[j]).m_flags;
max_flags = fld.m_flags;
}
}

Expand Down

0 comments on commit 8d0c4b5

Please sign in to comment.