Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Tom Tromey <tromey@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [patch] Accelerate blocks sorting
Date: Mon, 22 Jun 2009 19:51:00 -0000	[thread overview]
Message-ID: <20090622195128.GA8401@host0.dyn.jankratochvil.net> (raw)
In-Reply-To: <m3d48wnk7m.fsf@fleche.redhat.com>

On Mon, 22 Jun 2009 21:26:37 +0200, Tom Tromey wrote:
> Yeah.  It isn't the return, but the splitting.

I see it now, thanks for looking it up.

Checked-in.


Thanks,
Jan


http://sourceware.org/ml/gdb-cvs/2009-06/msg00135.html

--- src/gdb/ChangeLog	2009/06/22 18:17:01	1.10619
+++ src/gdb/ChangeLog	2009/06/22 19:50:10	1.10620
@@ -1,4 +1,10 @@
-2009-05-07  Sami Wagiaalla  <swagiaal@redhat.com>
+2009-06-22  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	PR gdb/9988:
+	* buildsym.c (block_compar): New function.
+	(end_symtab): Replace the bubble sort by a qsort based code.
+
+2009-06-22  Sami Wagiaalla  <swagiaal@redhat.com>
 
 	* MAINTAINERS (Write After Approval): Add self.
 
--- src/gdb/buildsym.c	2009/06/17 18:41:50	1.71
+++ src/gdb/buildsym.c	2009/06/22 19:50:10	1.72
@@ -899,6 +899,19 @@
     }
 }
 
+/* Helper function for qsort.  Parametes are `struct block *' pointers,
+   function sorts them in descending order by their BLOCK_START.  */
+
+static int
+block_compar (const void *ap, const void *bp)
+{
+  const struct block *a = *(const struct block **) ap;
+  const struct block *b = *(const struct block **) bp;
+
+  return ((BLOCK_START (b) > BLOCK_START (a))
+	  - (BLOCK_START (b) < BLOCK_START (a)));
+}
+
 /* Finish the symbol definitions for one main source file, close off
    all the lexical contexts for that file (creating struct block's for
    them), then make the struct symtab for that file and put it in the
@@ -952,32 +965,28 @@
      OBJF_REORDERED is true, then sort the pending blocks.  */
   if ((objfile->flags & OBJF_REORDERED) && pending_blocks)
     {
-      /* FIXME!  Remove this horrid bubble sort and use merge sort!!! */
-      int swapped;
-      do
-	{
-	  struct pending_block *pb, *pbnext;
+      unsigned count = 0;
+      struct pending_block *pb;
+      struct block **barray, **bp;
+      struct cleanup *back_to;
 
-	  pb = pending_blocks;
-	  pbnext = pb->next;
-	  swapped = 0;
+      for (pb = pending_blocks; pb != NULL; pb = pb->next)
+	count++;
 
-	  while (pbnext)
-	    {
-	      /* swap blocks if unordered! */
+      barray = xmalloc (sizeof (*barray) * count);
+      back_to = make_cleanup (xfree, barray);
 
-	      if (BLOCK_START (pb->block) < BLOCK_START (pbnext->block))
-		{
-		  struct block *tmp = pb->block;
-		  pb->block = pbnext->block;
-		  pbnext->block = tmp;
-		  swapped = 1;
-		}
-	      pb = pbnext;
-	      pbnext = pbnext->next;
-	    }
-	}
-      while (swapped);
+      bp = barray;
+      for (pb = pending_blocks; pb != NULL; pb = pb->next)
+	*bp++ = pb->block;
+
+      qsort (barray, count, sizeof (*barray), block_compar);
+
+      bp = barray;
+      for (pb = pending_blocks; pb != NULL; pb = pb->next)
+	pb->block = *bp++;
+
+      do_cleanups (back_to);
     }
 
   /* Cleanup any undefined types that have been left hanging around


      reply	other threads:[~2009-06-22 19:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-22 17:39 Jan Kratochvil
2009-06-22 18:15 ` Michael Snyder
2009-06-22 18:26   ` Jan Kratochvil
2009-06-22 18:26 ` Tom Tromey
2009-06-22 18:35   ` Jan Kratochvil
2009-06-22 19:26     ` Tom Tromey
2009-06-22 19:51       ` Jan Kratochvil [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090622195128.GA8401@host0.dyn.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox