* [PATCH] Make intrusive_list_node's next/prev private
@ 2022-04-08 19:42 Pedro Alves
2022-04-12 16:14 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Pedro Alves @ 2022-04-08 19:42 UTC (permalink / raw)
To: gdb-patches
Tromey noticed that intrusive_list_node leaves its data members
public, which seems sub-optimal.
This commit makes intrusive_list_node's data fields private.
intrusive_list_iterator, intrusive_list_reverse_iterator, and
intrusive_list do need to access the fields, so they are made friends.
Change-Id: Ia8b306b40344cc218d423c8dfb8355207a612ac5
---
gdbsupport/intrusive_list.h | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/gdbsupport/intrusive_list.h b/gdbsupport/intrusive_list.h
index 77eeeeec5fd..6812266159a 100644
--- a/gdbsupport/intrusive_list.h
+++ b/gdbsupport/intrusive_list.h
@@ -24,15 +24,26 @@
/* A list node. The elements put in an intrusive_list either inherit
from this, or have a field of this type. */
template<typename T>
-struct intrusive_list_node
+class intrusive_list_node
{
+public:
bool is_linked () const
{
return next != INTRUSIVE_LIST_UNLINKED_VALUE;
}
+private:
T *next = INTRUSIVE_LIST_UNLINKED_VALUE;
T *prev = INTRUSIVE_LIST_UNLINKED_VALUE;
+
+ template<typename T2, typename AsNode>
+ friend struct intrusive_list_iterator;
+
+ template<typename T2, typename AsNode>
+ friend struct intrusive_list_reverse_iterator;
+
+ template<typename T2, typename AsNode>
+ friend struct intrusive_list;
};
/* Follows a couple types used by intrusive_list as template parameter to find
base-commit: 9f184a64f51b00fd5c208c8528f6a553f5b27c1c
--
2.26.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Make intrusive_list_node's next/prev private
2022-04-08 19:42 [PATCH] Make intrusive_list_node's next/prev private Pedro Alves
@ 2022-04-12 16:14 ` Tom Tromey
2022-04-13 9:27 ` Pedro Alves
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2022-04-12 16:14 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:
Pedro> Tromey noticed that intrusive_list_node leaves its data members
Pedro> public, which seems sub-optimal.
Pedro> This commit makes intrusive_list_node's data fields private.
Pedro> intrusive_list_iterator, intrusive_list_reverse_iterator, and
Pedro> intrusive_list do need to access the fields, so they are made friends.
Looks good, thank you.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Make intrusive_list_node's next/prev private
2022-04-12 16:14 ` Tom Tromey
@ 2022-04-13 9:27 ` Pedro Alves
0 siblings, 0 replies; 3+ messages in thread
From: Pedro Alves @ 2022-04-13 9:27 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 2022-04-12 17:14, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:
>
> Pedro> Tromey noticed that intrusive_list_node leaves its data members
> Pedro> public, which seems sub-optimal.
>
> Pedro> This commit makes intrusive_list_node's data fields private.
> Pedro> intrusive_list_iterator, intrusive_list_reverse_iterator, and
> Pedro> intrusive_list do need to access the fields, so they are made friends.
>
> Looks good, thank you.
Thanks, merged.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-13 9:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-08 19:42 [PATCH] Make intrusive_list_node's next/prev private Pedro Alves
2022-04-12 16:14 ` Tom Tromey
2022-04-13 9:27 ` Pedro Alves
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).