Hi Canh,
Ack with comment
1)
Why not initialize all variables in the structs in initialization list? At
least for the lists where some variables are. More consistent
Example:
struct file_communicate {
bool request_f; /* True if pending request */
bool answer_f; /* True if pending answer */
bool timeout_f; /* True if API has got a timeout. Thread shall not answer */
lgsf_treq_t request_code; /* Request code from API */
int return_code; /* Return code from handlers */
void *indata_ptr; /* In-parameters for handlers */
size_t outdata_size;
void *outdata_ptr; /* Out data from handlers */
file_communicate() : request_code(LGSF_NOREQ)
{
answer_f = false;
request_f = false;
timeout_f = false;
return_code = LGSF_NORETC;
indata_ptr = NULL;
outdata_ptr = NULL;
outdata_size = 0;
}
};
Could be initialized as:
struct file_communicate {
bool request_f; /* True if pending request */
bool answer_f; /* True if pending answer */
bool timeout_f; /* True if API has got a timeout. Thread shall not answer */
lgsf_treq_t request_code; /* Request code from API */
int return_code; /* Return code from handlers */
void *indata_ptr; /* In-parameters for handlers */
size_t outdata_size;
void *outdata_ptr; /* Out data from handlers */
file_communicate() :
request_f(false),
answer_f(false),
timeout_f(false),
request_code(LGSF_NOREQ),
return_code(LGSF_NORETC),
indata_ptr(NULL),
outdata_size(0),
outdata_ptr(NULL)
{ }
};
> -----Original Message-----
> From: Canh Van Truong [mailto:[email protected]]
> Sent: den 31 augusti 2016 10:49
> To: Vu Minh Nguyen <[email protected]>; Lennart Lund
> <[email protected]>; [email protected]
> Cc: [email protected]
> Subject: [PATCH 1 of 1] log: fix cppcheck with performance severity [#1975]
>
> osaf/services/saf/logsv/lgs/lgs_config.cc | 35
> ++++++++++++------------------
> osaf/services/saf/logsv/lgs/lgs_file.cc | 4 +-
> 2 files changed, 16 insertions(+), 23 deletions(-)
>
>
> Fix performance reported by cppcheck.
>
> diff --git a/osaf/services/saf/logsv/lgs/lgs_config.cc
> b/osaf/services/saf/logsv/lgs/lgs_config.cc
> --- a/osaf/services/saf/logsv/lgs/lgs_config.cc
> +++ b/osaf/services/saf/logsv/lgs/lgs_config.cc
> @@ -137,32 +137,25 @@ typedef struct _lgs_conf_t {
> lgs_conf_flg_t logDataGroupname_cnfflag;
> lgs_conf_flg_t logStreamFileFormat_cnfflag;
>
> - _lgs_conf_t() {
> - /*
> - * For the following flags, LGS_CNF_DEF means that no external
> - * configuration exists and the corresponding attributes hard-coded
> - * default value is used.Is set to false if configuration is found in
> - * IMM object or environment variable.
> - * See function lgs_logconf_get() for more info.
> - */
> + _lgs_conf_t()
> + : logRootDirectory(lgs_conf_def.logRootDirectory),
> + logRootDirectory_cnfflag(LGS_CNF_DEF),
> + logMaxLogrecsize_cnfflag(LGS_CNF_DEF),
> + logStreamSystemHighLimit_cnfflag(LGS_CNF_DEF),
> + logStreamSystemLowLimit_cnfflag(LGS_CNF_DEF),
> + logStreamAppHighLimit_cnfflag(LGS_CNF_DEF),
> + logStreamAppLowLimit_cnfflag(LGS_CNF_DEF),
> + logMaxApplicationStreams_cnfflag(LGS_CNF_DEF),
> + logFileIoTimeout_cnfflag(LGS_CNF_DEF),
> + logFileSysConfig_cnfflag(LGS_CNF_DEF),
> + logDataGroupname_cnfflag(LGS_CNF_DEF),
> + logStreamFileFormat_cnfflag(LGS_CNF_DEF)
> + {
> OpenSafLogConfig_object_exist = false;
> - logRootDirectory_cnfflag = LGS_CNF_DEF;
> - logStreamSystemHighLimit_cnfflag = LGS_CNF_DEF;
> - logStreamSystemLowLimit_cnfflag = LGS_CNF_DEF;
> - logStreamAppHighLimit_cnfflag = LGS_CNF_DEF;
> - logStreamAppLowLimit_cnfflag = LGS_CNF_DEF;
> - logDataGroupname_cnfflag = LGS_CNF_DEF;
> /*
> * The following attributes cannot be configured in the config file
> * Will be set to false if the attribute exists in the IMM config object
> */
> - logMaxLogrecsize_cnfflag = LGS_CNF_DEF;
> - logMaxApplicationStreams_cnfflag = LGS_CNF_DEF;
> - logFileIoTimeout_cnfflag = LGS_CNF_DEF;
> - logFileSysConfig_cnfflag = LGS_CNF_DEF;
> - logStreamFileFormat_cnfflag = LGS_CNF_DEF;
> -
> - logRootDirectory = lgs_conf_def.logRootDirectory;
> (void) strcpy(logDataGroupname, lgs_conf_def.logDataGroupname);
> (void) strcpy(logStreamFileFormat, lgs_conf_def.logStreamFileFormat);
> logMaxLogrecsize = lgs_conf_def.logMaxLogrecsize;
> diff --git a/osaf/services/saf/logsv/lgs/lgs_file.cc
> b/osaf/services/saf/logsv/lgs/lgs_file.cc
> --- a/osaf/services/saf/logsv/lgs/lgs_file.cc
> +++ b/osaf/services/saf/logsv/lgs/lgs_file.cc
> @@ -51,11 +51,11 @@ struct file_communicate {
> size_t outdata_size;
> void *outdata_ptr; /* Out data from handlers */
>
> - file_communicate() {
> + file_communicate() : request_code(LGSF_NOREQ)
> + {
> answer_f = false;
> request_f = false;
> timeout_f = false;
> - request_code = LGSF_NOREQ;
> return_code = LGSF_NORETC;
> indata_ptr = NULL;
> outdata_ptr = NULL;
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel