Skip to contentSkip to conversation

Remove unnecessary zero-initialisations from *io.c

PATCH In review Colin Watson 2 participants 3 messages Jan 1, 2013 – Jan 7, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove unnecessary zero-initialisations from *io.c

This patch removes explicit zero-initialisations from *io.c in favour of grub_zalloc. Is there any good reason to initialise these explicitly? This reduces the size of all four of these modules on i386-pc as follows:

  bufio         -56
  gzio          -24
  lzopio        -20
  xzio          -64

2013-01-01 Colin Watson <[email protected]>

* grub-core/io/bufio.c (grub_bufio_open): Use grub_zalloc instead of explicitly zeroing elements.
* grub-core/io/gzio.c (grub_gzio_open): Likewise.
* grub-core/io/lzopio.c (grub_lzopio_open): Remove explicit zeroing of elements in a structure already allocated using grub_zalloc.
* grub-core/io/xzio.c (grub_xzio_open): Likewise.

=== modified file 'grub-core/io/bufio.c'

io/bufio.c +2 -6
@@ -48,7 +48,7 @@ grub_bufio_open (grub_file_t io, int siz
   grub_file_t file;
   grub_bufio_t bufio = 0;
 
-  file = (grub_file_t) grub_malloc (sizeof (*file));
+  file = (grub_file_t) grub_zalloc (sizeof (*file));
   if (! file)
     return 0;
 
@@ -61,7 +61,7 @@ grub_bufio_open (grub_file_t io, int siz
     size = ((io->size > GRUB_BUFIO_MAX_SIZE) ? GRUB_BUFIO_MAX_SIZE :
             io->size);
 
-  bufio = grub_malloc (sizeof (struct grub_bufio) + size);
+  bufio = grub_zalloc (sizeof (struct grub_bufio) + size);
   if (! bufio)
     {
       grub_free (file);
@@ -70,14 +70,10 @@ grub_bufio_open (grub_file_t io, int siz
 
   bufio->file = io;
   bufio->block_size = size;
-  bufio->buffer_len = 0;
-  bufio->buffer_at = 0;
 
   file->device = io->device;
-  file->offset = 0;
   file->size = io->size;
   file->data = bufio;
-  file->read_hook = 0;
   file->fs = &grub_bufio_fs;
   file->not_easily_seekable = io->not_easily_seekable;
 

=== modified file 'grub-core/io/gzio.c'

io/gzio.c +1 -3
@@ -1130,7 +1130,7 @@ grub_gzio_open (grub_file_t io)
   grub_file_t file;
   grub_gzio_t gzio = 0;
 
-  file = (grub_file_t) grub_malloc (sizeof (*file));
+  file = (grub_file_t) grub_zalloc (sizeof (*file));
   if (! file)
     return 0;
 
@@ -1144,9 +1144,7 @@ grub_gzio_open (grub_file_t io)
   gzio->file = io;
 
   file->device = io->device;
-  file->offset = 0;
   file->data = gzio;
-  file->read_hook = 0;
   file->fs = &grub_gzio_fs;
   file->not_easily_seekable = 1;
 

=== modified file 'grub-core/io/lzopio.c'

io/lzopio.c +0 -2
@@ -428,9 +428,7 @@ grub_lzopio_open (grub_file_t io)
   lzopio->file = io;
 
   file->device = io->device;
-  file->offset = 0;
   file->data = lzopio;
-  file->read_hook = 0;
   file->fs = &grub_lzopio_fs;
   file->size = GRUB_FILE_SIZE_UNKNOWN;
   file->not_easily_seekable = 1;

=== modified file 'grub-core/io/xzio.c'

io/xzio.c +0 -6
@@ -186,12 +186,9 @@ grub_xzio_open (grub_file_t io)
     }
 
   xzio->file = io;
-  xzio->saved_offset = 0;
 
   file->device = io->device;
-  file->offset = 0;
   file->data = xzio;
-  file->read_hook = 0;
   file->fs = &grub_xzio_fs;
   file->size = GRUB_FILE_SIZE_UNKNOWN;
   file->not_easily_seekable = 1;
@@ -210,10 +207,7 @@ grub_xzio_open (grub_file_t io)
     }
 
   xzio->buf.in = xzio->inbuf;
-  xzio->buf.in_pos = 0;
-  xzio->buf.in_size = 0;
   xzio->buf.out = xzio->outbuf;
-  xzio->buf.out_pos = 0;
   xzio->buf.out_size = XZBUFSIZ;
 
   /* FIXME: don't test footer on not easily seekable files.  */

Thanks,

Signature · 1 line
Colin Watson                                       [[email protected]]
#1 lore raw
Quoted 9 lines · Colin Watson

This patch removes explicit zero-initialisations from *io.c in favour of grub_zalloc. Is there any good reason to initialise these explicitly? This reduces the size of all four of these modules on i386-pc as follows:

  bufio         -56
  gzio          -24
  lzopio        -20
  xzio          -64

Go ahead.

Quoted 114 lines

2013-01-01 Colin Watson <[email protected]>

* grub-core/io/bufio.c (grub_bufio_open): Use grub_zalloc instead of explicitly zeroing elements.
* grub-core/io/gzio.c (grub_gzio_open): Likewise.
* grub-core/io/lzopio.c (grub_lzopio_open): Remove explicit zeroing of elements in a structure already allocated using grub_zalloc.
* grub-core/io/xzio.c (grub_xzio_open): Likewise.

=== modified file 'grub-core/io/bufio.c'

io/bufio.c +2 -6
@@ -48,7 +48,7 @@ grub_bufio_open (grub_file_t io, int siz
   grub_file_t file;
   grub_bufio_t bufio = 0;
 
-  file = (grub_file_t) grub_malloc (sizeof (*file));
+  file = (grub_file_t) grub_zalloc (sizeof (*file));
   if (! file)
     return 0;
 
@@ -61,7 +61,7 @@ grub_bufio_open (grub_file_t io, int siz
     size = ((io->size > GRUB_BUFIO_MAX_SIZE) ? GRUB_BUFIO_MAX_SIZE :
             io->size);
 
-  bufio = grub_malloc (sizeof (struct grub_bufio) + size);
+  bufio = grub_zalloc (sizeof (struct grub_bufio) + size);
   if (! bufio)
     {
       grub_free (file);
@@ -70,14 +70,10 @@ grub_bufio_open (grub_file_t io, int siz
 
   bufio->file = io;
   bufio->block_size = size;
-  bufio->buffer_len = 0;
-  bufio->buffer_at = 0;
 
   file->device = io->device;
-  file->offset = 0;
   file->size = io->size;
   file->data = bufio;
-  file->read_hook = 0;
   file->fs = &grub_bufio_fs;
   file->not_easily_seekable = io->not_easily_seekable;
 

=== modified file 'grub-core/io/gzio.c'

io/gzio.c +1 -3
@@ -1130,7 +1130,7 @@ grub_gzio_open (grub_file_t io)
   grub_file_t file;
   grub_gzio_t gzio = 0;
 
-  file = (grub_file_t) grub_malloc (sizeof (*file));
+  file = (grub_file_t) grub_zalloc (sizeof (*file));
   if (! file)
     return 0;
 
@@ -1144,9 +1144,7 @@ grub_gzio_open (grub_file_t io)
   gzio->file = io;
 
   file->device = io->device;
-  file->offset = 0;
   file->data = gzio;
-  file->read_hook = 0;
   file->fs = &grub_gzio_fs;
   file->not_easily_seekable = 1;
 

=== modified file 'grub-core/io/lzopio.c'

io/lzopio.c +0 -2
@@ -428,9 +428,7 @@ grub_lzopio_open (grub_file_t io)
   lzopio->file = io;
 
   file->device = io->device;
-  file->offset = 0;
   file->data = lzopio;
-  file->read_hook = 0;
   file->fs = &grub_lzopio_fs;
   file->size = GRUB_FILE_SIZE_UNKNOWN;
   file->not_easily_seekable = 1;

=== modified file 'grub-core/io/xzio.c'

io/xzio.c +0 -6
@@ -186,12 +186,9 @@ grub_xzio_open (grub_file_t io)
     }
 
   xzio->file = io;
-  xzio->saved_offset = 0;
 
   file->device = io->device;
-  file->offset = 0;
   file->data = xzio;
-  file->read_hook = 0;
   file->fs = &grub_xzio_fs;
   file->size = GRUB_FILE_SIZE_UNKNOWN;
   file->not_easily_seekable = 1;
@@ -210,10 +207,7 @@ grub_xzio_open (grub_file_t io)
     }
 
   xzio->buf.in = xzio->inbuf;
-  xzio->buf.in_pos = 0;
-  xzio->buf.in_size = 0;
   xzio->buf.out = xzio->outbuf;
-  xzio->buf.out_pos = 0;
   xzio->buf.out_size = XZBUFSIZ;
 
   /* FIXME: don't test footer on not easily seekable files.  */

Thanks,

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#2 lore raw
Quoted 6 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 5 lines · Colin Watson

This patch removes explicit zero-initialisations from *io.c in favour of grub_zalloc. Is there any good reason to initialise these explicitly? This reduces the size of all four of these modules on i386-pc as follows:

Quoted 6 lines
Quoted 4 lines
  bufio         -56
  gzio          -24
  lzopio        -20
  xzio          -64

Go ahead.

Committed, thanks.

Signature · 1 line
Colin Watson                                       [[email protected]]