Performance improvement: move call to strlen outside loop

This commit is contained in:
Shahram Najm 2016-02-10 09:52:41 +00:00
parent e64f649fe1
commit f37734820c
2 changed files with 10 additions and 5 deletions

View File

@ -156,11 +156,13 @@ static int unpack_string(grib_accessor* a, char* val, size_t *len)
int is_missing = 0;
const char* uname = NULL;
const char* tempname = NULL;
size_t uname_len = 0;
uname = grib_arguments_get_string(grib_handle_of_accessor(a),self->args,carg++);
sprintf(result,"%s","");
uname_len = strlen(uname);
for(i=0;i<strlen(uname);i++)
for(i=0; i<uname_len; i++)
{
if(uname[i]=='%'){
int precision=999;

View File

@ -75,7 +75,7 @@ static void init()
}
#endif
int grib_recompose_name(grib_handle* h, grib_accessor *observer, const char* uname, char* fname,int fail)
int grib_recompose_name(grib_handle* h, grib_accessor *observer, const char* uname, char* fname, int fail)
{
grib_accessor* a;
char loc[1024]={0,};
@ -87,10 +87,11 @@ int grib_recompose_name(grib_handle* h, grib_accessor *observer, const char* una
long lval=0;
int type=GRIB_TYPE_STRING;
size_t replen = 0;
const size_t uname_len = strlen(uname);
loc[0] = 0 ;
fname[0] = 0 ;
for(i=0;i<strlen(uname);i++)
for(i=0; i<uname_len; i++)
{
if(mode > -1)
{
@ -400,10 +401,11 @@ int grib_recompose_print(grib_handle* h, grib_accessor *observer, const char* un
int maxcolsd=8;
int maxcols;
int newline=1;
const size_t uname_len = strlen(uname);
maxcols=maxcolsd;
loc[0] = 0 ;
for(i=0;i<strlen(uname);i++)
for(i=0; i<uname_len; i++)
{
if(mode > -1)
{
@ -792,7 +794,8 @@ grib_action* grib_parse_file( grib_context* gc,const char* filename)
return af->root;
}
int grib_type_to_int(char id) {
int grib_type_to_int(char id)
{
switch (id) {
case 'd':
return GRIB_TYPE_DOUBLE;