From: Dominik Csapak <d.csapak@proxmox.com>
To: yew-devel@lists.proxmox.com
Subject: [yew-devel] [PATCH yew-widget-toolkit 3/3] state: keyed slab tree: panic on inserting duplicate keys in debug mode
Date: Mon, 29 Sep 2025 15:12:11 +0200 [thread overview]
Message-ID: <20250929131219.2932214-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20250929131219.2932214-1-d.csapak@proxmox.com>
check on insert/append if the keys already exist, but only in debug mode
to not unnecessarily slow down release builds.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/state/tree_store/keyed_slab_tree.rs | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/state/tree_store/keyed_slab_tree.rs b/src/state/tree_store/keyed_slab_tree.rs
index df163a2..c7044d1 100644
--- a/src/state/tree_store/keyed_slab_tree.rs
+++ b/src/state/tree_store/keyed_slab_tree.rs
@@ -449,6 +449,12 @@ impl<T> KeyedSlabTree<T> {
.append_subtree_node(subtree, subtree_node, level, parent);
let key_cache = self.calculate_cache(node_id);
+ #[cfg(debug_assertions)]
+ for key in key_cache.keys() {
+ if self.key_cache.contains_key(key) {
+ panic!("append_subtree_node: duplicate key {key:?}");
+ }
+ }
self.key_cache.extend(key_cache);
node_id
@@ -519,6 +525,10 @@ impl<T> KeyedSlabTree<T> {
fn insert_record(&mut self, record: T, parent_id: Option<usize>) -> usize {
let key = self.extract_key(&record);
let node_id = self.tree.insert_record(record, parent_id);
+ #[cfg(debug_assertions)]
+ if self.key_cache.contains_key(&key) {
+ panic!("insert_record: duplicate key {key:?}");
+ }
self.key_cache.insert(key, node_id);
node_id
}
--
2.47.3
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
next prev parent reply other threads:[~2025-09-29 13:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-29 13:12 [yew-devel] [PATCH yew-widget-toolkit 1/3] state: keyed slab tree: fix typo Dominik Csapak
2025-09-29 13:12 ` [yew-devel] [PATCH yew-widget-toolkit 2/3] state: keyed slab tree: add key -> node_id cache Dominik Csapak
2025-09-29 13:12 ` Dominik Csapak [this message]
2025-10-03 6:22 ` [yew-devel] applied: [PATCH yew-widget-toolkit 1/3] state: keyed slab tree: fix typo Dietmar Maurer
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=20250929131219.2932214-3-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=yew-devel@lists.proxmox.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