From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Vladimir Prus <vladimir@codesourcery.com>
Cc: Tom Tromey <tromey@redhat.com>, gdb-patches@sourceware.org
Subject: [patch 4/4] varobj_list replacement, choice 3 of 3: Iterator optimization
Date: Fri, 10 Jul 2009 22:12:00 -0000 [thread overview]
Message-ID: <20090710201902.GE7014@host0.dyn.jankratochvil.net> (raw)
In-Reply-To: <200907021409.39886.vladimir@codesourcery.com>
Hi,
just a minor optimization - in fact only to keep its algorithm complexity on
par with "choice 1 of 3: VEC_safe_push + VEC_unordered_remove".
Thanks,
Jan
gdb/
2009-07-10 Jan Kratochvil <jan.kratochvil@redhat.com>
Optimize O(n) varobj_root unlinking to O(1).
* varobj.c (struct varobj_root): New field prev.
(install_variable): New variable root. Initialize the new field prev.
(uninstall_variable): Remove the variables cr, prer. Replace the
element lookup by O(1) unlink using the new field prev.
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -98,8 +98,8 @@ struct varobj_root
/* The varobj for this root node. */
struct varobj *rootvar;
- /* Next root variable */
- struct varobj_root *next;
+ /* Next and previous root variable (NULL for the last or first item). */
+ struct varobj_root *next, *prev;
};
/* Every variable in the system has a structure of this type defined
@@ -1708,12 +1708,17 @@ install_variable (struct varobj *var)
/* If root, add varobj to root list */
if (is_root_p (var))
{
- /* Add to list of root variables */
- if (rootlist == NULL)
- var->root->next = NULL;
- else
- var->root->next = rootlist;
- rootlist = var->root;
+ struct varobj_root *root = var->root;
+
+ /* Add to list of root variables. */
+
+ root->next = rootlist;
+ rootlist = root;
+
+ if (root->next)
+ root->next->prev = root;
+
+ root->prev = NULL;
}
return 1; /* OK */
@@ -1725,8 +1730,6 @@ uninstall_variable (struct varobj *var)
{
struct vlist *cv;
struct vlist *prev;
- struct varobj_root *cr;
- struct varobj_root *prer;
const char *chp;
unsigned int index = 0;
unsigned int i = 1;
@@ -1766,30 +1769,17 @@ uninstall_variable (struct varobj *var)
/* If root, remove varobj from root list */
if (is_root_p (var))
{
- /* Remove from list of root variables */
- if (rootlist == var->root)
- rootlist = var->root->next;
+ struct varobj_root *root = var->root;
+
+ /* Remove from list of root variables. */
+
+ if (root->prev)
+ root->prev->next = root->next;
else
- {
- prer = NULL;
- cr = rootlist;
- while ((cr != NULL) && (cr->rootvar != var))
- {
- prer = cr;
- cr = cr->next;
- }
- if (cr == NULL)
- {
- warning
- ("Assertion failed: Could not find varobj \"%s\" in root list",
- var->obj_name);
- return;
- }
- if (prer == NULL)
- rootlist = NULL;
- else
- prer->next = cr->next;
- }
+ rootlist = root->next;
+
+ if (root->next)
+ root->next->prev = root->prev;
}
}
prev parent reply other threads:[~2009-07-10 20:21 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-25 8:02 [patch 4/8] Types GC [varobj_list to all_root_varobjs] Jan Kratochvil
2009-06-09 20:50 ` Tom Tromey
2009-07-02 8:39 ` Jan Kratochvil
2009-07-02 10:09 ` Vladimir Prus
2009-07-04 21:11 ` Jan Kratochvil
2009-07-07 8:54 ` Vladimir Prus
2009-07-07 9:32 ` Jan Kratochvil
2009-07-10 20:17 ` [patch 0/4] varobj_list replacement [Re: [patch 4/8] Types GC [varobj_list to all_root_varobjs]] Jan Kratochvil
2009-07-29 21:34 ` Tom Tromey
2009-07-30 8:46 ` Vladimir Prus
2009-07-30 14:00 ` Jan Kratochvil
2009-07-30 15:13 ` Vladimir Prus
2009-07-30 15:16 ` Jan Kratochvil
2009-07-10 20:18 ` [patch 1/4] varobj_list replacement, choice 1 of 3: VEC_safe_push + VEC_unordered_remove Jan Kratochvil
2009-07-10 20:21 ` [patch 2/4] varobj_list replacement, choice 2 of 3: VEC_safe_insert + VEC_ordered_remove Jan Kratochvil
2009-07-10 21:11 ` [patch 3/4] varobj_list replacement, choice 3 of 3: Iterator Jan Kratochvil
2009-07-10 22:12 ` 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=20090710201902.GE7014@host0.dyn.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=tromey@redhat.com \
--cc=vladimir@codesourcery.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