[4/3+] coff-go32-exe: avoid reallocating stub on copy

Message ID 20200325175438.11596-1-jwjagersma@gmail.com
State New
Headers show
Series
  • [4/3+] coff-go32-exe: avoid reallocating stub on copy
Related show

Commit Message

H.J. Lu via Binutils March 25, 2020, 5:54 p.m.
I'd like to make a small addition to this patch set:
When copying the stub from one bfd to another, there is no need to
reallocate if the destination already has a stub that is the same size
as the source.  This will practically always be the case.

bfd/
2020-03-25  Jan W. Jagersma  <jwjagersma@gmail.com>

	* coff-stgo32.c (go32exe_copy_private_bfd_data): Avoid realloc
	when possible.
---
 bfd/coff-stgo32.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

-- 
2.25.2

Patch

diff --git a/bfd/coff-stgo32.c b/bfd/coff-stgo32.c
index 7239b34306..d1be578c6a 100644
--- a/bfd/coff-stgo32.c
+++ b/bfd/coff-stgo32.c
@@ -217,8 +217,9 @@  go32exe_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
   /* Make sure we have a source stub.  */
   BFD_ASSERT (coff_data (ibfd)->stub != NULL);
 
-  /* Allocate the output stub.  */
-  coff_data (obfd)->stub = bfd_alloc (obfd, coff_data (ibfd)->stub_size);
+  /* Reallocate the output stub if necessary.  */
+  if (coff_data (ibfd)->stub_size > coff_data (obfd)->stub_size)
+    coff_data (obfd)->stub = bfd_alloc (obfd, coff_data (ibfd)->stub_size);
   if (coff_data (obfd)->stub == NULL)
     return FALSE;