You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by dv...@apache.org on 2006/11/27 10:32:08 UTC

svn commit: r479556 - in /xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg: SVGOMAnimateElement.java SVGOMFontElement.java SVGOMLineElement.java SVGOMRectElement.java

Author: dvholten
Date: Mon Nov 27 01:32:07 2006
New Revision: 479556

URL: http://svn.apache.org/viewvc?view=rev&rev=479556
Log:
speedup getAttributeType by using a Map for lookup from attribute-name-string to svg-type-int.
more to follow.

Modified:
    xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMAnimateElement.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMFontElement.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMLineElement.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMRectElement.java

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMAnimateElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMAnimateElement.java?view=diff&rev=479556&r1=479555&r2=479556
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMAnimateElement.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMAnimateElement.java Mon Nov 27 01:32:07 2006
@@ -24,6 +24,9 @@
 import org.w3c.dom.Node;
 import org.w3c.dom.svg.SVGAnimateElement;
 
+import java.util.Map;
+import java.util.HashMap;
+
 /**
  * This class implements {@link SVGAnimateElement}.
  *
@@ -35,6 +38,55 @@
     implements SVGAnimateElement {
 
     /**
+     * this map supports a fast lookup from svg-attribute-name string to
+     * svgType-integer. It is faster than doing string-equals in a
+     * lengthy if-else-statement.
+     * This map is used only by {@link #getAttributeType }
+     */
+    private static final Map typeMap = new HashMap();
+
+
+    static {
+
+        Map map = typeMap;
+
+        Integer svgType = new Integer( SVGTypes.TYPE_IDENT );
+        map.put(  SVG_ACCUMULATE_ATTRIBUTE, svgType );
+        map.put(  SVG_ADDITIVE_ATTRIBUTE, svgType );
+        map.put(  SVG_ATTRIBUTE_TYPE_ATTRIBUTE, svgType );
+        map.put(  SVG_CALC_MODE_ATTRIBUTE, svgType );
+        map.put(  SVG_FILL_ATTRIBUTE, svgType );
+        map.put(  SVG_RESTART_ATTRIBUTE, svgType );
+
+        svgType = new Integer( SVGTypes.TYPE_CDATA );
+        map.put(  SVG_ATTRIBUTE_NAME_ATTRIBUTE, svgType );
+        map.put(  SVG_BY_ATTRIBUTE, svgType );
+        map.put(  SVG_FROM_ATTRIBUTE, svgType );
+        map.put(  SVG_MAX_ATTRIBUTE, svgType );
+        map.put(  SVG_MIN_ATTRIBUTE, svgType );
+        map.put(  SVG_TO_ATTRIBUTE, svgType );
+        map.put(  SVG_VALUES_ATTRIBUTE, svgType );
+
+        svgType = new Integer( SVGTypes.TYPE_TIMING_SPECIFIER_LIST );
+        map.put(  SVG_BEGIN_ATTRIBUTE, svgType );
+        map.put(  SVG_END_ATTRIBUTE, svgType );
+
+        svgType = new Integer( SVGTypes.TYPE_TIME );
+        map.put(  SVG_DUR_ATTRIBUTE, svgType );
+        map.put(  SVG_REPEAT_DUR_ATTRIBUTE, svgType );
+
+        svgType = new Integer( SVGTypes.TYPE_NUMBER_LIST );
+        map.put(  SVG_KEY_SPLINES_ATTRIBUTE, svgType );
+        map.put(  SVG_KEY_TIMES_ATTRIBUTE, svgType );
+
+        svgType = new Integer( SVGTypes.TYPE_INTEGER );
+        map.put(  SVG_REPEAT_COUNT_ATTRIBUTE, svgType );
+
+    }
+
+
+
+    /**
      * Creates a new SVGOMAnimateElement object.
      */
     protected SVGOMAnimateElement() {
@@ -70,33 +122,12 @@
      * Returns the type of the given attribute.
      */
     public int getAttributeType(String ns, String ln) {
+
         if (ns == null) {
-            if (ln.equals(SVG_ACCUMULATE_ATTRIBUTE)
-                    || ln.equals(SVG_ADDITIVE_ATTRIBUTE)
-                    || ln.equals(SVG_ATTRIBUTE_TYPE_ATTRIBUTE)
-                    || ln.equals(SVG_CALC_MODE_ATTRIBUTE)
-                    || ln.equals(SVG_FILL_ATTRIBUTE)
-                    || ln.equals(SVG_RESTART_ATTRIBUTE)) {
-                return SVGTypes.TYPE_IDENT;
-            } else if (ln.equals(SVG_ATTRIBUTE_NAME_ATTRIBUTE)
-                    || ln.equals(SVG_BY_ATTRIBUTE)
-                    || ln.equals(SVG_FROM_ATTRIBUTE)
-                    || ln.equals(SVG_MAX_ATTRIBUTE)
-                    || ln.equals(SVG_MIN_ATTRIBUTE)
-                    || ln.equals(SVG_TO_ATTRIBUTE)
-                    || ln.equals(SVG_VALUES_ATTRIBUTE)) {
-                return SVGTypes.TYPE_CDATA;
-            } else if (ln.equals(SVG_BEGIN_ATTRIBUTE)
-                    || ln.equals(SVG_END_ATTRIBUTE)) {
-                return SVGTypes.TYPE_TIMING_SPECIFIER_LIST;
-            } else if (ln.equals(SVG_DUR_ATTRIBUTE)
-                    || ln.equals(SVG_REPEAT_DUR_ATTRIBUTE)) {
-                return SVGTypes.TYPE_TIME;
-            } else if (ln.equals(SVG_KEY_SPLINES_ATTRIBUTE)
-                    || ln.equals(SVG_KEY_TIMES_ATTRIBUTE)) {
-                return SVGTypes.TYPE_NUMBER_LIST;
-            } else if (ln.equals(SVG_REPEAT_COUNT_ATTRIBUTE)) {
-                return SVGTypes.TYPE_INTEGER;
+            Integer typeCode = (Integer)typeMap.get( ln );
+            if ( typeCode != null ){
+                // it is one of 'my' mappings..
+                return typeCode.intValue();
             }
         }
         return super.getAttributeType(ns, ln);

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMFontElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMFontElement.java?view=diff&rev=479556&r1=479555&r2=479556
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMFontElement.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMFontElement.java Mon Nov 27 01:32:07 2006
@@ -26,6 +26,9 @@
 import org.w3c.dom.svg.SVGAnimatedBoolean;
 import org.w3c.dom.svg.SVGFontElement;
 
+import java.util.Map;
+import java.util.HashMap;
+
 /**
  * This class implements {@link SVGFontElement}.
  *
@@ -35,7 +38,34 @@
 public class SVGOMFontElement
     extends    SVGStylableElement
     implements SVGFontElement {
-    
+
+
+
+    /**
+     * this map supports a fast lookup from svg-attribute-name string to
+     * svgType-integer. It is faster than doing string-equals in a
+     * lengthy if-else-statement.
+     * This map is used only by {@link #getAttributeType }
+     */
+    private static final Map typeMap = new HashMap();
+
+
+    static {
+
+        Map map = typeMap;
+
+        SVGOMAttributeInfo svgType = new SVGOMAttributeInfo( SVGTypes.TYPE_NUMBER, false );
+
+        map.put(  SVG_HORIZ_ORIGIN_X_ATTRIBUTE, svgType );
+        map.put(  SVG_HORIZ_ORIGIN_Y_ATTRIBUTE, svgType );
+        map.put(  SVG_HORIZ_ADV_X_ATTRIBUTE, svgType );
+        map.put(  SVG_VERT_ORIGIN_X_ATTRIBUTE, svgType );
+        map.put(  SVG_VERT_ORIGIN_Y_ATTRIBUTE, svgType );
+        map.put(  SVG_VERT_ADV_Y_ATTRIBUTE, svgType );
+
+    }
+
+
     /**
      * Creates a new SVGOMFontElement object.
      */
@@ -80,6 +110,8 @@
 
     /**
      * Returns whether the given XML attribute is animatable.
+     * Because in this class only one attribute is animatable,
+     * we dont use the lookup table for animatable.
      */
     public boolean isAttributeAnimatable(String ns, String ln) {
         if (ns == null) {
@@ -93,7 +125,7 @@
     /**
      * Returns the type of the given attribute.
      */
-    public int getAttributeType(String ns, String ln) {
+    public int OLDgetAttributeType(String ns, String ln) {
         if (ns == null) {
             if (ln.equals(SVG_HORIZ_ORIGIN_X_ATTRIBUTE)
                     || ln.equals(SVG_HORIZ_ORIGIN_Y_ATTRIBUTE)
@@ -102,6 +134,21 @@
                     || ln.equals(SVG_VERT_ORIGIN_Y_ATTRIBUTE)
                     || ln.equals(SVG_VERT_ADV_Y_ATTRIBUTE)) {
                 return SVGTypes.TYPE_NUMBER;
+            }
+        }
+        return super.getAttributeType(ns, ln);
+    }
+
+    /**
+     * Returns the type of the given attribute.
+     */
+    public int getAttributeType(String ns, String ln) {
+
+        if (ns == null) {
+            SVGOMAttributeInfo typeCode = (SVGOMAttributeInfo)typeMap.get( ln );
+            if ( typeCode != null ){
+                // it is one of 'my' mappings..
+                return typeCode.getSVGType();
             }
         }
         return super.getAttributeType(ns, ln);

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMLineElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMLineElement.java?view=diff&rev=479556&r1=479555&r2=479556
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMLineElement.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMLineElement.java Mon Nov 27 01:32:07 2006
@@ -26,6 +26,9 @@
 import org.w3c.dom.svg.SVGAnimatedLength;
 import org.w3c.dom.svg.SVGLineElement;
 
+import java.util.Map;
+import java.util.HashMap;
+
 /**
  * This class implements {@link SVGLineElement}.
  *
@@ -36,6 +39,29 @@
     extends    SVGGraphicsElement
     implements SVGLineElement {
 
+
+    /**
+     * this map supports a fast lookup from svg-attribute-name string to
+     * svgType-integer. It is faster than doing string-equals in a
+     * lengthy if-else-statement.
+     * This map is used only by {@link #getAttributeType }
+     */
+    private static final Map typeMap = new HashMap();
+
+
+    static {
+
+        Map map = typeMap;
+
+        SVGOMAttributeInfo svgType = new SVGOMAttributeInfo( SVGTypes.TYPE_LENGTH, true );
+
+        map.put(  SVG_X1_ATTRIBUTE, svgType );
+        map.put(  SVG_Y1_ATTRIBUTE, svgType );
+        map.put(  SVG_X2_ATTRIBUTE, svgType );
+        map.put(  SVG_Y2_ATTRIBUTE, svgType );
+
+    }
+
     /**
      * Creates a new SVGOMLineElement object.
      */
@@ -65,7 +91,7 @@
         return getAnimatedLengthAttribute
             (null, SVG_X1_ATTRIBUTE, SVG_LINE_X1_DEFAULT_VALUE,
              SVGOMAnimatedLength.HORIZONTAL_LENGTH, false);
-    } 
+    }
 
     /**
      * <b>DOM</b>: Implements {@link SVGLineElement#getY1()}.
@@ -83,7 +109,7 @@
         return getAnimatedLengthAttribute
             (null, SVG_X2_ATTRIBUTE, SVG_LINE_X2_DEFAULT_VALUE,
              SVGOMAnimatedLength.HORIZONTAL_LENGTH, false);
-    } 
+    }
 
     /**
      * <b>DOM</b>: Implements {@link SVGLineElement#getY2()}.
@@ -92,7 +118,7 @@
         return getAnimatedLengthAttribute
             (null, SVG_Y2_ATTRIBUTE, SVG_LINE_Y2_DEFAULT_VALUE,
              SVGOMAnimatedLength.VERTICAL_LENGTH, false);
-    } 
+    }
 
     /**
      * Returns a new uninitialized instance of this object's class.
@@ -106,7 +132,7 @@
     /**
      * Returns whether the given XML attribute is animatable.
      */
-    public boolean isAttributeAnimatable(String ns, String ln) {
+    public boolean OLDisAttributeAnimatable(String ns, String ln) {
         if (ns == null) {
             if (ln.equals(SVG_X1_ATTRIBUTE)
                     || ln.equals(SVG_Y1_ATTRIBUTE)
@@ -119,15 +145,30 @@
     }
 
     /**
+     * Returns whether the given XML attribute is animatable.
+     */
+    public boolean isAttributeAnimatable(String ns, String ln) {
+        if (ns == null) {
+            SVGOMAttributeInfo typeCode = (SVGOMAttributeInfo)typeMap.get( ln );
+            if ( typeCode != null ){
+                // it is one of 'my' mappings..
+                return typeCode.getIsAnimatable();
+            }
+        }
+        return super.isAttributeAnimatable(ns, ln);
+    }
+
+
+    /**
      * Returns the type of the given attribute.
      */
     public int getAttributeType(String ns, String ln) {
+
         if (ns == null) {
-            if (ln.equals(SVG_X1_ATTRIBUTE)
-                    || ln.equals(SVG_Y1_ATTRIBUTE)
-                    || ln.equals(SVG_X2_ATTRIBUTE)
-                    || ln.equals(SVG_Y2_ATTRIBUTE)) {
-                return SVGTypes.TYPE_LENGTH;
+            SVGOMAttributeInfo typeCode = (SVGOMAttributeInfo)typeMap.get( ln );
+            if ( typeCode != null ){
+                // it is one of 'my' mappings..
+                return typeCode.getSVGType();
             }
         }
         return super.getAttributeType(ns, ln);

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMRectElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMRectElement.java?view=diff&rev=479556&r1=479555&r2=479556
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMRectElement.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMRectElement.java Mon Nov 27 01:32:07 2006
@@ -27,6 +27,9 @@
 import org.w3c.dom.svg.SVGAnimatedLength;
 import org.w3c.dom.svg.SVGRectElement;
 
+import java.util.Map;
+import java.util.HashMap;
+
 /**
  * This class implements {@link SVGRectElement}.
  *
@@ -37,6 +40,32 @@
     extends    SVGGraphicsElement
     implements SVGRectElement {
 
+
+    /**
+     * this map supports a fast lookup from svg-attribute-name string to
+     * svgType-integer. It is faster than doing string-equals in a
+     * lengthy if-else-statement.
+     * This map is used only by {@link #getAttributeType }
+     */
+    private static final Map typeMap = new HashMap();
+
+
+    static {
+
+        Map map = typeMap;
+
+        SVGOMAttributeInfo svgType = new SVGOMAttributeInfo( SVGTypes.TYPE_LENGTH, true );
+
+        map.put(  SVG_X_ATTRIBUTE, svgType );
+        map.put(  SVG_Y_ATTRIBUTE, svgType );
+        map.put(  SVG_RX_ATTRIBUTE, svgType );
+        map.put(  SVG_RY_ATTRIBUTE, svgType );
+        map.put(  SVG_WIDTH_ATTRIBUTE, svgType );
+        map.put(  SVG_HEIGHT_ATTRIBUTE, svgType );
+
+    }
+
+
     /**
      * Creates a new SVGOMRectElement object.
      */
@@ -66,7 +95,7 @@
         return getAnimatedLengthAttribute
             (null, SVG_X_ATTRIBUTE, SVG_RECT_X_DEFAULT_VALUE,
              SVGOMAnimatedLength.HORIZONTAL_LENGTH, false);
-    } 
+    }
 
     /**
      * <b>DOM</b>: Implements {@link SVGRectElement#getY()}.
@@ -84,7 +113,7 @@
         return getAnimatedLengthAttribute
             (null, SVG_WIDTH_ATTRIBUTE, "",
              SVGOMAnimatedLength.HORIZONTAL_LENGTH, true);
-    } 
+    }
 
     /**
      * <b>DOM</b>: Implements {@link SVGRectElement#getHeight()}.
@@ -128,7 +157,7 @@
                                   (LiveAttributeValue)result);
         }
         return result;
-    } 
+    }
 
     /**
      * <b>DOM</b>: Implements {@link SVGRectElement#getRy()}.
@@ -163,7 +192,7 @@
                                   (LiveAttributeValue)result);
         }
         return result;
-    } 
+    }
 
     /**
      * Returns a new uninitialized instance of this object's class.
@@ -176,8 +205,9 @@
 
     /**
      * Returns whether the given XML attribute is animatable.
+     * to be removed
      */
-    public boolean isAttributeAnimatable(String ns, String ln) {
+    public boolean OLDisAttributeAnimatable(String ns, String ln) {
         if (ns == null) {
             if (ln.equals(SVG_X_ATTRIBUTE)
                     || ln.equals(SVG_Y_ATTRIBUTE)
@@ -193,8 +223,9 @@
 
     /**
      * Returns the type of the given attribute.
+     * to be removed
      */
-    public int getAttributeType(String ns, String ln) {
+    public int OLDgetAttributeType(String ns, String ln) {
         if (ns == null) {
             if (ln.equals(SVG_X_ATTRIBUTE)
                     || ln.equals(SVG_Y_ATTRIBUTE)
@@ -207,6 +238,37 @@
         }
         return super.getAttributeType(ns, ln);
     }
+
+    /**
+     * Returns whether the given XML attribute is animatable.
+     */
+    public boolean isAttributeAnimatable(String ns, String ln) {
+        if (ns == null) {
+            SVGOMAttributeInfo typeCode = (SVGOMAttributeInfo)typeMap.get( ln );
+            if ( typeCode != null ){
+                // it is one of 'my' mappings..
+                return typeCode.getIsAnimatable();
+            }
+        }
+        return super.isAttributeAnimatable(ns, ln);
+    }
+
+
+    /**
+     * Returns the type of the given attribute.
+     */
+    public int getAttributeType(String ns, String ln) {
+
+        if (ns == null) {
+            SVGOMAttributeInfo typeCode = (SVGOMAttributeInfo)typeMap.get( ln );
+            if ( typeCode != null ){
+                // it is one of 'my' mappings..
+                return typeCode.getSVGType();
+            }
+        }
+        return super.getAttributeType(ns, ln);
+    }
+
 
     // AnimationTarget ///////////////////////////////////////////////////////