From e285a4742f9d98800d5f94b55325db2b43c39210 Mon Sep 17 00:00:00 2001 From: Federico Aponte Date: Fri, 26 Apr 2024 12:52:12 +0200 Subject: [PATCH] refactor: minor change in for loops Signed-off-by: Federico Aponte --- userspace/libsinsp/base64.h | 1 - userspace/libsinsp/filter.cpp | 4 +--- userspace/libsinsp/sinsp_filtercheck.cpp | 12 ++++++------ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/userspace/libsinsp/base64.h b/userspace/libsinsp/base64.h index a74d15877a..2627c3c45c 100644 --- a/userspace/libsinsp/base64.h +++ b/userspace/libsinsp/base64.h @@ -19,7 +19,6 @@ #pragma once -#include #include #include diff --git a/userspace/libsinsp/filter.cpp b/userspace/libsinsp/filter.cpp index b044d41e79..ac778c5b19 100644 --- a/userspace/libsinsp/filter.cpp +++ b/userspace/libsinsp/filter.cpp @@ -531,10 +531,8 @@ std::list 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) diff --git a/userspace/libsinsp/sinsp_filtercheck.cpp b/userspace/libsinsp/sinsp_filtercheck.cpp index 47e6fa5d9c..955d5cad78 100644 --- a/userspace/libsinsp/sinsp_filtercheck.cpp +++ b/userspace/libsinsp/sinsp_filtercheck.cpp @@ -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; @@ -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; } }