From d42771007184ba98fbce48351b49dbf9a57bf634 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sat, 19 Oct 2024 17:23:39 -0400 Subject: [PATCH] src/svgtiny_css.c: don't check "key" in the libdom user_data handler The libdom user data get/set functions in the libcss select handler API identify the libcss user data (among all potential user data) with a key -- basically, a string. In theory, we should look for this key in the callback function before delegating to libcss (to make sure it's libcss user data we're working with), but at the moment, libcss is the only place the data could have come from. We can therefore skip the key comparison entirely. This simplifies the code a bit because it's currently awkward to access the same interned key string from all three sites. --- src/svgtiny_css.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/svgtiny_css.c b/src/svgtiny_css.c index bbef58d..612dab9 100644 --- a/src/svgtiny_css.c +++ b/src/svgtiny_css.c @@ -1930,18 +1930,17 @@ static void svgtiny_dom_user_data_handler(dom_node_operation operation, dom_string *key, void *data, struct dom_node *src, struct dom_node *dst) { - /* We only care about the userdata that is identified by our - * userdata key. Unfortunately I see no obvious way to obtain - * the copy of the userdata key that is already interned in - * svgtiny_strings.h; so we duplicate it here (ugh). */ - dom_string *str; - dom_string_create((const uint8_t *)"_libcss_user_data", 17, &str); - if (dom_string_isequal(str,key) == false || data == NULL) { - /* Wrong key, or no data */ - dom_string_destroy(str); + /* Technically we should compare "key" against the one used in + * get/set_libcss_node_data(), but at the moment libcss is the + * only user of this libdom feature, and eliding the compare + * saves us the trouble of figuring out how to reference that + * interned_userdata_key from this handler. */ + UNUSED(key); + + if (data == NULL) { + /* No data */ return; } - dom_string_destroy(str); /* Check the DOM operation, and make the corresponding call to * css_libcss_node_data_handler(). No error handling is done. -- 2.44.2