PR23282, Reinstate seek optimization
authorAlan Modra <amodra@gmail.com>
Wed, 13 Jun 2018 14:27:17 +0000 (23:57 +0930)
committerAlan Modra <amodra@gmail.com>
Thu, 14 Jun 2018 02:02:01 +0000 (11:32 +0930)
PR 23282
* bfdio.c (bfd_seek): Optimize away seeks to current position.

bfd/ChangeLog
bfd/bfdio.c

index 8b70682..d9465d5 100644 (file)
@@ -1,3 +1,8 @@
+2018-06-14  Alan Modra  <amodra@gmail.com>
+
+       PR 23282
+       * bfdio.c (bfd_seek): Optimize away seeks to current position.
+
 2018-06-13  Scott Egerton  <scott.egerton@imgtec.com>
            Faraz Shahbazker  <Faraz.Shahbazker@mips.com>
 
index 136fa8b..1f4caca 100644 (file)
@@ -330,6 +330,10 @@ bfd_seek (bfd *abfd, file_ptr position, int direction)
   if (direction != SEEK_CUR)
     position += offset;
 
+  if ((direction == SEEK_CUR && position == 0)
+      || (direction == SEEK_SET && (ufile_ptr) position == abfd->where))
+    return 0;
+
   result = abfd->iovec->bseek (abfd, position, direction);
   if (result != 0)
     {