Changeset 15904 in josm for trunk


Ignore:
Timestamp:
2020-02-22T19:40:29+01:00 (4 years ago)
Author:
simon04
Message:

see #18749 - SVGElement: store String instead of StyleAttribute in map

Location:
trunk/src/com/kitfox/svg
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/kitfox/svg/SVGElement.java

    r15901 r15904  
    8989     * Styles defined for this elemnt via the <b>style</b> attribute.
    9090     */
    91     protected final HashMap<String, StyleAttribute> inlineStyles = new HashMap<>();
     91    protected final HashMap<String, String> inlineStyles = new HashMap<>();
    9292    /**
    9393     * Presentation attributes set for this element. Ie, any attribute other
    9494     * than the <b>style</b> attribute.
    9595     */
    96     protected final HashMap<String, StyleAttribute> presAttribs = new HashMap<>();
     96    protected final HashMap<String, String> presAttributes = new HashMap<>();
    9797    /**
    9898     * A list of presentation attributes to not include in the presentation
     
    273273        if (style != null)
    274274        {
    275             HashMap<?, ?> map = XMLParseUtil.parseStyle(style, inlineStyles);
     275            XMLParseUtil.parseStyle(style, inlineStyles);
    276276        }
    277277
     
    299299            String value = attrs.getValue(i);
    300300
    301             presAttribs.put(name, new StyleAttribute(name, value == null ? null : value.intern()));
     301            presAttributes.put(name, value == null ? null : value.intern());
    302302        }
    303303    }
     
    316316    public Set<String> getPresentationAttributes()
    317317    {
    318         return presAttribs.keySet();
     318        return presAttributes.keySet();
    319319    }
    320320
     
    486486
    487487        //Check for local inline styles
    488         StyleAttribute styAttr = inlineStyles.get(styName);
    489 
    490         attrib.setStringValue(styAttr == null ? "" : styAttr.getStringValue());
     488        String styAttr = inlineStyles.get(styName);
     489
     490        attrib.setStringValue(styAttr == null ? "" : styAttr);
    491491
    492492        //Return if we've found a non animated style
     
    498498
    499499        //Check for presentation attribute
    500         StyleAttribute presAttr = presAttribs.get(styName);
    501 
    502         attrib.setStringValue(presAttr == null ? "" : presAttr.getStringValue());
     500        String presAttr = presAttributes.get(styName);
     501
     502        attrib.setStringValue(presAttr == null ? "" : presAttr);
    503503
    504504        //Return if we've found a presentation attribute instead
     
    546546    {
    547547        //Check for local inline styles
    548         return inlineStyles.get(styName);
     548        final String value = inlineStyles.get(styName);
     549        return value != null ? new StyleAttribute(styName, value) : null;
    549550    }
    550551
     
    561562
    562563        //Make sure we have a coresponding presentation attribute
    563         StyleAttribute presAttr = presAttribs.get(presName);
     564        String presAttr = presAttributes.get(presName);
    564565
    565566        //Copy presentation value directly
    566         attrib.setStringValue(presAttr == null ? "" : presAttr.getStringValue());
     567        attrib.setStringValue(presAttr == null ? "" : presAttr);
    567568
    568569        //Return if we found presentation attribute
    569         if (presAttr != null)
    570         {
    571             return true;
    572         }
    573 
    574         return false;
     570        return presAttr != null;
    575571    }
    576572
     
    584580    {
    585581        //Check for local inline styles
    586         return presAttribs.get(styName);
     582        final String value = presAttributes.get(styName);
     583        return value != null ? new StyleAttribute(styName, value) : null;
    587584    }
    588585
  • trunk/src/com/kitfox/svg/xml/XMLParseUtil.java

    r14598 r15904  
    302302     * @param map - A map to which these styles will be added
    303303     */
    304     public static HashMap<String, StyleAttribute> parseStyle(String styleString, HashMap<String, StyleAttribute> map) {
     304    public static void parseStyle(String styleString, HashMap<String, String> map) {
    305305        final Pattern patSemi = Pattern.compile(";");
    306306
    307         String[] styles = patSemi.split(styleString);
    308 
    309         for (int i = 0; i < styles.length; i++)
    310         {
    311             if (styles[i].length() == 0)
    312             {
    313                 continue;
    314             }
    315 
    316             int colon = styles[i].indexOf(':');
    317             if (colon == -1)
    318             {
    319                 continue;
    320             }
    321 
    322             String key = styles[i].substring(0, colon).trim().intern();
    323             String value = quoteMatch.reset(styles[i].substring(colon + 1).trim()).replaceAll("").intern();
    324 
    325             map.put(key, new StyleAttribute(key, value));
    326         }
    327 
    328         return map;
     307        // com.kitfox.svg.xml.StyleAttribute    58,595 (3.6%)   1,992,230 B (1.4%)      n/a
     308        patSemi.splitAsStream(styleString)
     309                .filter(style -> !style.isEmpty())
     310                .forEach(style  -> {
     311                    int colon = style.indexOf(':');
     312                    if (colon == -1) return;
     313                    String key = style.substring(0, colon).trim().intern();
     314                    String value = quoteMatch.reset(style.substring(colon + 1).trim()).replaceAll("").intern();
     315                    map.put(key, value);
     316                });
    329317    }
    330318}
Note: See TracChangeset for help on using the changeset viewer.