[librsvg: 8/12] state: simply store the Attribute in the important_styles hashset



commit 40b16cc5f48d78cf42915a92e14166e90709be18
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Apr 22 10:56:01 2018 +0200

    state: simply store the Attribute in the important_styles hashset
    
    Instead of propagating down the string with the attribute's name

 librsvg/rsvg-styles.c       | 22 +++++++++++-----------
 rsvg_internals/build.rs     |  2 +-
 rsvg_internals/src/state.rs | 18 +++++-------------
 3 files changed, 17 insertions(+), 25 deletions(-)
---
diff --git a/librsvg/rsvg-styles.c b/librsvg/rsvg-styles.c
index e0a17b53..ff017a83 100644
--- a/librsvg/rsvg-styles.c
+++ b/librsvg/rsvg-styles.c
@@ -51,8 +51,8 @@ extern char *rsvg_state_rust_get_clip_path(const State *state);
 extern char *rsvg_state_rust_get_filter(const State *state);
 extern char *rsvg_state_rust_get_mask(const State *state);
 
-extern gboolean rsvg_state_rust_contains_important_style(State *state, const gchar *name);
-extern gboolean rsvg_state_rust_insert_important_style(State *state, const gchar *name);
+extern gboolean rsvg_state_rust_contains_important_style(State *state, RsvgAttribute attr);
+extern gboolean rsvg_state_rust_insert_important_style(State *state, RsvgAttribute attr);
 
 extern gboolean rsvg_state_rust_parse_style_pair(State *state, RsvgAttribute attr, const char *value, 
gboolean accept_shorthands)
     G_GNUC_WARN_UNUSED_RESULT;
@@ -326,7 +326,6 @@ typedef enum {
 
 static gboolean
 rsvg_parse_style_pair (RsvgState *state,
-                       const gchar *name,
                        RsvgAttribute attr,
                        const gchar *value,
                        gboolean important,
@@ -335,7 +334,6 @@ rsvg_parse_style_pair (RsvgState *state,
 /* Parse a CSS2 style argument, setting the SVG context attributes. */
 static gboolean
 rsvg_parse_style_pair (RsvgState *state,
-                       const gchar *name,
                        RsvgAttribute attr,
                        const gchar *value,
                        gboolean important,
@@ -343,14 +341,14 @@ rsvg_parse_style_pair (RsvgState *state,
 {
     gboolean success = TRUE;
 
-    if (name == NULL || value == NULL)
+    if (value == NULL)
         return success;
 
     if (!important) {
-        if (rsvg_state_rust_contains_important_style (state->state_rust, name))
+        if (rsvg_state_rust_contains_important_style (state->state_rust, attr))
             return success;
     } else {
-        rsvg_state_rust_insert_important_style (state->state_rust, name);
+        rsvg_state_rust_insert_important_style (state->state_rust, attr);
     }
 
     switch (attr) {
@@ -487,7 +485,7 @@ rsvg_parse_presentation_attributes (RsvgState * state, RsvgPropertyBag * atts)
     iter = rsvg_property_bag_iter_begin (atts);
 
     while (success && rsvg_property_bag_iter_next (iter, &key, &attr, &value)) {
-        success = rsvg_parse_style_pair (state, key, attr, value, FALSE, PAIR_SOURCE_PRESENTATION_ATTRIBUTE);
+        success = rsvg_parse_style_pair (state, attr, value, FALSE, PAIR_SOURCE_PRESENTATION_ATTRIBUTE);
     }
 
     rsvg_property_bag_iter_end (iter);
@@ -568,7 +566,6 @@ rsvg_parse_style_attribute_contents (RsvgState *state, const char *str)
 
                 if (rsvg_attribute_from_name (first_value, &attr)) {
                     success = rsvg_parse_style_pair (state,
-                                                     first_value,
                                                      attr,
                                                      style_value,
                                                      important,
@@ -828,8 +825,11 @@ apply_style (const gchar *key, StyleValueData *value, gpointer user_data)
     RsvgAttribute attr;
 
     if (rsvg_attribute_from_name (key, &attr)) {
-        gboolean success = rsvg_parse_style_pair (
-            state, key, attr, value->value, value->important, PAIR_SOURCE_STYLE);
+        gboolean success = rsvg_parse_style_pair (state,
+                                                  attr,
+                                                  value->value,
+                                                  value->important,
+                                                  PAIR_SOURCE_STYLE);
         /* FIXME: propagate errors upstream */
     }
 }
diff --git a/rsvg_internals/build.rs b/rsvg_internals/build.rs
index 4ce9beba..49957447 100644
--- a/rsvg_internals/build.rs
+++ b/rsvg_internals/build.rs
@@ -168,7 +168,7 @@ fn generate_phf_of_svg_attributes() {
     let mut file = BufWriter::new(File::create(&path).unwrap());
 
     writeln!(&mut file, "#[repr(C)]").unwrap();
-    writeln!(&mut file, "#[derive(Debug, Clone, Copy, PartialEq)]").unwrap();
+    writeln!(&mut file, "#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]").unwrap();
     writeln!(&mut file, "pub enum Attribute {{").unwrap();
 
     for &(_, valname) in attribute_defs.iter() {
diff --git a/rsvg_internals/src/state.rs b/rsvg_internals/src/state.rs
index f2c9d475..542f2be5 100644
--- a/rsvg_internals/src/state.rs
+++ b/rsvg_internals/src/state.rs
@@ -80,7 +80,7 @@ pub struct State {
     pub xml_lang: Option<XmlLang>,
     pub xml_space: Option<XmlSpace>,
 
-    important_styles: RefCell<HashSet<String>>,
+    important_styles: RefCell<HashSet<Attribute>>,
     cond: bool,
 }
 
@@ -1079,26 +1079,18 @@ pub extern "C" fn rsvg_state_rust_clone(state: *const State) -> *mut State {
 #[no_mangle]
 pub extern "C" fn rsvg_state_rust_contains_important_style(
     state: *const State,
-    name: *const libc::c_char,
+    attr: Attribute,
 ) -> glib_sys::gboolean {
     let state = unsafe { &*state };
-    let name = unsafe { utf8_cstr(name) };
 
-    state.important_styles.borrow().contains(name).to_glib()
+    state.important_styles.borrow().contains(&attr).to_glib()
 }
 
 #[no_mangle]
-pub extern "C" fn rsvg_state_rust_insert_important_style(
-    state: *mut State,
-    name: *const libc::c_char,
-) {
+pub extern "C" fn rsvg_state_rust_insert_important_style(state: *mut State, attr: Attribute) {
     let state = unsafe { &mut *state };
-    let name = unsafe { utf8_cstr(name) };
 
-    state
-        .important_styles
-        .borrow_mut()
-        .insert(String::from(name));
+    state.important_styles.borrow_mut().insert(attr);
 }
 
 #[no_mangle]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]