public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] Make ar faster
@ 2023-05-03 15:23 Nick Clifton
  0 siblings, 0 replies; only message in thread
From: Nick Clifton @ 2023-05-03 15:23 UTC (permalink / raw)
  To: bfd-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a2243c30bc13c9adce71d70eeb5e97b7846b48f3

commit a2243c30bc13c9adce71d70eeb5e97b7846b48f3
Author: Oleg Tolmatcev <oleg.tolmatcev@gmail.com>
Date:   Wed May 3 16:23:13 2023 +0100

    Make ar faster
    
     * archive.c (_bfd_write_archive_contents): Use a larger buffer in order to improve efficiency.

Diff:
---
 bfd/ChangeLog |  5 +++++
 bfd/archive.c | 21 ++++++++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 61a488c348b..013386d6007 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2023-05-03  Oleg Tolmatcev  <oleg.tolmatcev@gmail.com>
+
+	* archive.c (_bfd_write_archive_contents): Use a larger buffer in
+	order to improve efficiency.
+
 2023-05-03  Oleg Tolmatcev  <oleg.tolmatcev@gmail.com>
 
 	* coffcode.h (coff_read_word_from_buffer): New function.
diff --git a/bfd/archive.c b/bfd/archive.c
index 273a1b3b241..f6cae7a5b1b 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -2142,6 +2142,7 @@ _bfd_write_archive_contents (bfd *arch)
   bfd_size_type wrote;
   int tries;
   char *armag;
+  char *buffer = NULL;
 
   /* Verify the viability of all entries; if any of them live in the
      filesystem (as opposed to living in an archive open for input)
@@ -2222,16 +2223,23 @@ _bfd_write_archive_contents (bfd *arch)
 	}
     }
 
+#define AR_WRITE_BUFFERSIZE (DEFAULT_BUFFERSIZE * 1024)
+
+  /* FIXME: Find a way to test link_info.reduce_memory_overheads
+     and change the buffer size.  */
+  buffer = bfd_malloc (AR_WRITE_BUFFERSIZE);
+  if (buffer == NULL)
+    goto input_err;
+
   for (current = arch->archive_head;
        current != NULL;
        current = current->archive_next)
     {
-      char buffer[DEFAULT_BUFFERSIZE];
       bfd_size_type remaining = arelt_size (current);
 
       /* Write ar header.  */
       if (!_bfd_write_ar_hdr (arch, current))
-	return false;
+	goto input_err;
       if (bfd_is_thin_archive (arch))
 	continue;
       if (bfd_seek (current, (file_ptr) 0, SEEK_SET) != 0)
@@ -2239,7 +2247,7 @@ _bfd_write_archive_contents (bfd *arch)
 
       while (remaining)
 	{
-	  size_t amt = DEFAULT_BUFFERSIZE;
+	  size_t amt = AR_WRITE_BUFFERSIZE;
 
 	  if (amt > remaining)
 	    amt = remaining;
@@ -2247,17 +2255,19 @@ _bfd_write_archive_contents (bfd *arch)
 	  if (bfd_bread (buffer, amt, current) != amt)
 	    goto input_err;
 	  if (bfd_bwrite (buffer, amt, arch) != amt)
-	    return false;
+	    goto input_err;
 	  remaining -= amt;
 	}
 
       if ((arelt_size (current) % 2) == 1)
 	{
 	  if (bfd_bwrite (&ARFMAG[1], 1, arch) != 1)
-	    return false;
+	    goto input_err;
 	}
     }
 
+  free (buffer);
+
   if (makemap && hasobjects)
     {
       /* Verify the timestamp in the archive file.  If it would not be
@@ -2281,6 +2291,7 @@ _bfd_write_archive_contents (bfd *arch)
 
  input_err:
   bfd_set_input_error (current, bfd_get_error ());
+  free (buffer);
   return false;
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-03 15:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-03 15:23 [binutils-gdb] Make ar faster Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).