Changeset 14643 in josm for trunk/src/com


Ignore:
Timestamp:
2019-01-05T18:49:33+01:00 (6 years ago)
Author:
Don-vip
Message:

optimize parsing by creating static regex patterns (patch by dpolivaev)

See https://github.com/blackears/svgSalamander/pull/38

File:
1 edited

Legend:

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

    r14328 r14643  
    586586    }
    587587
     588    private static final Pattern TRANSFORM_PATTERN = Pattern.compile("\\w+\\([^)]*\\)");
    588589    static protected AffineTransform parseTransform(String val) throws SVGException
    589590    {
    590         final Matcher matchExpression = Pattern.compile("\\w+\\([^)]*\\)").matcher("");
     591        final Matcher matchExpression = TRANSFORM_PATTERN.matcher("");
    591592
    592593        AffineTransform retXform = new AffineTransform();
     
    601602    }
    602603
     604    private static final Pattern WORD_PATTERN = Pattern.compile("([a-zA-Z]+|-?\\d+(\\.\\d+)?(e-?\\d+)?|-?\\.\\d+(e-?\\d+)?)");
    603605    static public AffineTransform parseSingleTransform(String val) throws SVGException
    604606    {
    605         final Matcher matchWord = Pattern.compile("([a-zA-Z]+|-?\\d+(\\.\\d+)?(e-?\\d+)?|-?\\.\\d+(e-?\\d+)?)").matcher("");
     607        final Matcher matchWord = WORD_PATTERN.matcher("");
    606608
    607609        AffineTransform retXform = new AffineTransform();
     
    682684    }
    683685
     686    private static final Pattern COMMAND_PATTERN = Pattern.compile("([MmLlHhVvAaQqTtCcSsZz])|([-+]?((\\d*\\.\\d+)|(\\d+))([eE][-+]?\\d+)?)");
    684687    static protected PathCommand[] parsePathList(String list)
    685688    {
    686         final Matcher matchPathCmd = Pattern.compile("([MmLlHhVvAaQqTtCcSsZz])|([-+]?((\\d*\\.\\d+)|(\\d+))([eE][-+]?\\d+)?)").matcher(list);
     689        final Matcher matchPathCmd = COMMAND_PATTERN.matcher(list);
    687690
    688691        //Tokenize
Note: See TracChangeset for help on using the changeset viewer.