]> gitweb.michael.orlitzky.com - libsvgtiny.git/commitdiff
src/svgtiny{.c,_internal.h}: intern SVG's XML namespace URI
authorMichael Orlitzky <michael@orlitzky.com>
Sat, 7 Jun 2025 14:58:40 +0000 (10:58 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 9 Jun 2025 01:12:53 +0000 (21:12 -0400)
Intern the string "http://www.w3.org/2000/svg" in the parser state for
later use in libcss's node_name() select handler.

src/svgtiny.c
src/svgtiny_internal.h

index b566768fedb3823737f1b8445ecfebe5a3675201..361c43b9ecda871035311fc6e96d797541389879 100644 (file)
@@ -1234,6 +1234,19 @@ initialise_parse_state(struct svgtiny_parse_state *state,
 #include "svgtiny_strings.h"
 #undef SVGTINY_STRING_ACTION2
 
+       /* Intern SVG's xmlns separately because it's an lwc_string
+        * and not a dom_string. We initialise its pointer to NULL
+        * because, during finalisation, the test to see if it needs
+        * to be free'd looks for NULL. Returning a LIBDOM_ERROR on
+        * failure is not perfect but it's the closest of the
+        * available options. */
+       state->interned_svg_xmlns = NULL;
+       if (lwc_intern_string("http://www.w3.org/2000/svg",
+                               26,
+                               &state->interned_svg_xmlns) != lwc_error_ok) {
+               return svgtiny_LIBDOM_ERROR;
+       }
+
        /* get graphic dimensions */
        state->viewport_width = viewport_width;
        state->viewport_height = viewport_height;
@@ -1277,6 +1290,10 @@ static svgtiny_code finalise_parse_state(struct svgtiny_parse_state *state)
 #include "svgtiny_strings.h"
 #undef SVGTINY_STRING_ACTION2
 
+       if (state->interned_svg_xmlns != NULL) {
+               lwc_string_unref(state->interned_svg_xmlns);
+       }
+
        css_code = css_select_ctx_destroy(state->select_ctx);
        if (css_code != CSS_OK) {
                return svgtiny_LIBCSS_ERROR;
index 7874053e5b8d94e234110efabb4da234a289bc8b..641bc58d596b0c25c1d4bcdbaa3f0f8da87961a9 100644 (file)
@@ -75,6 +75,14 @@ struct svgtiny_parse_state {
 #include "svgtiny_strings.h"
 #undef SVGTINY_STRING_ACTION2
 
+       /* Where we store the interned copy of the SVG XML namespace,
+        *
+        *   http://www.w3.org/2000/svg
+        *
+        * We handle it separately it has a different type
+        * (lwc_string) than those above (dom_string).
+        */
+       lwc_string *interned_svg_xmlns;
 };
 
 struct svgtiny_list;