[Zlib-devel] TR: another version

Gilles Vollant info at winimage.com
Fri Jan 8 13:57:45 EST 2010


Just to inform people on the list who read the message about the gets
history

-----Message d'origine-----
De : Scott_Riley at amat.com [mailto:Scott_Riley at amat.com] 
Envoyé : vendredi 8 janvier 2010 19:47
À : Gilles Vollant
Objet : RE: another version

Hi Gilles,

I implemented your code changes below and saw an incredible improvement.
The time it took to read and process the compressed file was the same as
the uncompressed file; however my logs showed that it missed processing the
last 14 lines of the compressed file. I will analyze and debug this issue
after lunch. I am sure it is something minor and I will figure it out.

I just wanted to update you on the performance improvement.

"Awesome!!!"

Thank you for your extra effort on this issue.

Regards,
Scott



                                                                          
                                                                          
                                                                          
                                                                       To 
    "Gilles Vollant"                    Scott Riley/APPLIED               
    <info at winimage.com>                 MATERIALS at AMAT                    
                                                                       cc 
    01/07/2010 05:02 PM                                                   
                                                                  Subject 
                                        RE: another version               
                                                                          
                                                                          


De : Gilles Vollant [mailto:info at winimage.com] 
Envoyé : vendredi 8 janvier 2010 00:58
À : 'Scott_Riley at amat.com'
Objet : another version

must be faster, and allow you enlarge BUFFER_IN_CACHE_SIZE without slowing
with a BUFFER_IN_CACHE_SIZE set to 0x1000, this must be faster



struct {
      unsigned char buffer_gets->tab_in[BUFFER_IN_CACHE_SIZE];
      size_t pos_read_ascii_in_file ;
      size_t size_read_ascii_in_file ;

} buffer_gets_t;



void ZEXPORT init_buffer_gets_t(struct buffer_gets_t* buffer_gets)
{
    buffer_gets->pos_read_ascii_in_file = 0;
    buffer_gets->size_read_ascii_in_file = 0;
}

char* ZEXPORT strop_gzgets_buffered(struct buffer_gets_t* buffer_gets,char
*line_buffer,int i_is_size,int nchars,flatfile_t *flatfile_p)
{
    gzseek(flatfile_p->gz_file_p, -1 *
(long)(buffer_gets->size_read_ascii_in_file - (i+1)),SEEK_CUR);
    buffer_gets->pos_read_ascii_in_file = 0;
    buffer_gets->size_read_ascii_in_file = 0;
}

char* ZEXPORT dau_gzgets_buffered(struct buffer_gets_t* buffer_gets,char
*line_buffer,int i_is_size,int nchars,flatfile_t *flatfile_p)
{
      char *b = line_buffer;
      int pos_in_char_line = 0;

      if ((i_is_size != 0) && (nchars == 0))
            return NULL;

      for (;;)
      {
            int size_to_read_binary = BUFFER_IN_CACHE_SIZE;
            if (i_is_size != 0)
            {
                  if ((nchars-1) < BUFFER_IN_CACHE_SIZE)
                        size_to_read_binary = nchars-1;
            }

            if ((size_to_read_binary>0) &&
(buffer_gets->size_read_ascii_in_file ==
buffer_gets->pos_read_ascii_in_file))
            {
            //    buffer_gets->size_read_ascii_in_file =
fread(&buffer_gets->tab_in[0],1,(size_t)size_to_read_binary,f);
                  buffer_gets->pos_read_ascii_in_file = 0;
                  buffer_gets->size_read_ascii_in_file =
gzread(flatfile_p->gz_file_p, &buffer_gets->tab_in[0], size_to_read_binary);
            }

            if (buffer_gets->size_read_ascii_in_file<=0)
            {
                  if (pos_in_char_line == 0)
                           return NULL;
                  else
                  {
                        line_buffer[pos_in_char_line]='\0';
                        return b == line_buffer && pos_in_char_line > 0 ? b:
NULL;
                  }
            }

            if (buffer_gets->size_read_ascii_in_file > 0)
            {
                  int i;
                  for
(i=(int)buffer_gets->pos_read_ascii_in_file;i<(int)buffer_gets->size_read_as
cii_in_file;i++)
                  {
                        char c;
                        c = (((char)buffer_gets->tab_in[(i)])) ;

                        if (c!=0x0d)
                        {
                              if (c=='\n')
                              {
                              //    fseek(f,-1 *
(long)(buffer_gets->size_read_ascii_in_file- (i+1)),SEEK_CUR);
                                   // gzseek(flatfile_p->gz_file_p, -1 *
(long)(buffer_gets->size_read_ascii_in_file - (i+1)),SEEK_CUR);

                       
                                    if (i_is_size != 0)
                                   {
                                          /* only if you want \n at end of
string:
 
line_buffer[pos_in_char_line++]='\n';*/
                                    }
                                    buffer_gets->pos_read_ascii_in_file =
i+1;
                                    line_buffer[pos_in_char_line] ='\0';
                                    return b == line_buffer &&
pos_in_char_line > 0 ? b : NULL;
                              }

                              if ((i_is_size == 1) && (pos_in_char_line ==
(nchars-1)))
                              {
                              //    fseek(f, -1 *
(long)(buffer_gets->size_read_ascii_in_file - i),SEEK_CUR);
                                   /* gzseek(flatfile_p->gz_file_p,-1
*(long)(buffer_gets->size_read_ascii_in_file - i),SEEK_CUR); */
                                    buffer_gets->pos_read_ascii_in_file = i;

                                    line_buffer[pos_in_char_line]='\0';
                                    return b == line_buffer &&
pos_in_char_line > 0 ? b : NULL;
                              }

                              line_buffer[pos_in_char_line++] = c;
                        }
                  }
            }
            buffer_gets->pos_read_ascii_in_file = 0;
            buffer_gets->size_read_ascii_in_file = 0;
      }

      return b == line_buffer && pos_in_char_line > 0 ? b : NULL; 
}






More information about the Zlib-devel mailing list