[Sie-announce] SIEコード [2207] SVGElementの処理を高速化

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 12月 4日 (土) 23:00:33 JST


Revision: 2207
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=2207
Author:   dhrname
Date:     2010-12-04 23:00:33 +0900 (Sat, 04 Dec 2010)

Log Message:
-----------
SVGElementの処理を高速化
1, parseFloat()を+()のように記号を使って置き換えた
2, /\d/のような正規表現オブジェクトは最初に作っておいた

Modified Paths:
--------------
    branches/06x/065/org/w3c/dom/svg.js

Modified: branches/06x/065/org/w3c/dom/svg.js
===================================================================
--- branches/06x/065/org/w3c/dom/svg.js	2010-12-04 12:14:04 UTC (rev 2206)
+++ branches/06x/065/org/w3c/dom/svg.js	2010-12-04 14:00:33 UTC (rev 2207)
@@ -149,7 +149,7 @@
     if (evt.eventPhase === Event.BUBBLING_PHASE) {
       return;
     }
-    var name = evt.attrName, tar = evt.target, _parseFloat = parseFloat;
+    var name = evt.attrName, tar = evt.target;
     if (!!CSS2Properties[name] || name.indexOf("-") > -1) { //スタイルシートのプロパティならば
       tar._attributeStyle.setProperty(name, evt.newValue, "");
       tar._currentStyle = null;  //キャッシュは消しておく
@@ -157,9 +157,9 @@
     if (evt.relatedNode.localName === "id") { //xml:idあるいはid属性ならば
       tar.id = evt.newValue;
     } else if (name === "transform" && !!tar.transform) {
-      var tft = evt.newValue, degR = /[\-\d\.e]+/g;
-      var coma = tft.match(/[A-Za-z]+(?=\s*\()/g);   //コマンド文字にマッチ translate
-      var list = tft.match(/\([^\)]+\)/g);           //カッコ内のリストにマッチ (10 20 30...)
+      var tft = evt.newValue, degR = tar._degReg;
+      var coma = tft.match(tar._comaReg);   //コマンド文字にマッチ translate
+      var list = tft.match(tar._strReg);           //カッコ内のリストにマッチ (10 20 30...)
       var a,b,c,d,e,f,lis,deg,rad,degli;
       //transform属性の値を、SVGTransformListであるtransformプロパティに結びつける
       for (var j=0,cli=coma.length;j<cli;j++) {
@@ -169,22 +169,22 @@
         degli = deg.length;
         if (degli === 6) {
           var cm = s.matrix;
-          cm.a = _parseFloat(deg[0]);
-          cm.b = _parseFloat(deg[1]);
-          cm.c = _parseFloat(deg[2]);
-          cm.d = _parseFloat(deg[3]);
-          cm.e = _parseFloat(deg[4]);
-          cm.f = _parseFloat(deg[5]);
+          cm.a = +(deg[0]);
+          cm.b = +(deg[1]);
+          cm.c = +(deg[2]);
+          cm.d = +(deg[3]);
+          cm.e = +(deg[4]);
+          cm.f = +(deg[5]);
         } else {
           if (degli === 3) {
             var degz = _parseFloat(deg[0]);
-            s.setRotate(degz, _parseFloat(deg[1]), _parseFloat(deg[2]))
+            s.setRotate(degz, +(deg[1]), +(deg[2]))
           } else if (degli <= 2) {
-            var degz = _parseFloat(deg[0]);
+            var degz = +(deg[0]);
             if (com === "translate") {
-              s.setTranslate(degz, _parseFloat(deg[1] || 0));
+              s.setTranslate(degz, +(deg[1] || 0));
             } else if (com === "scale") {
-              s.setScale(degz, _parseFloat(deg[1] || deg[0]));
+              s.setScale(degz, +(deg[1] || deg[0]));
             } else if (com === "rotate") {
               s.setRotate(degz, 0, 0);
             } else if (com === "skewX") {
@@ -203,9 +203,9 @@
       style.cssText = sc;
       if (sc !== "") {
         //style属性値の解析
-        sc = sc.replace(/^[^a-z\-]+/, "")
-               .replace(/\:\s+/g, ":")
-               .replace(/\s*;[^a-z\-]*/g, ";");
+        sc = sc.replace(tar._shouReg, "")
+               .replace(tar._conReg, ":")
+               .replace(tar._bouReg, ";");
         var a = sc.split(";");
         for (var i=0, ali=a.length;i<ali;++i) {
           var ai = a[i], m = ai.split(":");
@@ -254,7 +254,7 @@
       if (!!tar[name]) {
         var tea = tar[name], tod = tar.ownerDocument.documentElement;
         if (tea instanceof SVGAnimatedLength) {
-          var n = evt.newValue.match(/\D+$/), type = SVGLength.SVG_LENGTHTYPE_NUMBER;
+          var n = evt.newValue.match(tar._NaNReg), type = SVGLength.SVG_LENGTHTYPE_NUMBER, _parseFloat = parseFloat;
           if (!!n) {
             n = n[0];
           }
@@ -308,6 +308,14 @@
 SVGElement.constructor = Element;
 SVGElement.prototype = new Element();
 
+SVGElement.prototype._degReg = /[\-\d\.e]+/g;
+SVGElement.prototype._comaReg = /[A-Za-z]+(?=\s*\()/g;
+SVGElement.prototype._strReg =  /\([^\)]+\)/g;
+SVGElement.prototype._syouReg = /^[^a-z\-]+/;
+SVGElement.prototype._conReg = /\:\s+/g;
+SVGElement.prototype._bouReg = /\s*;[^a-z\-]*/g;
+SVGElement.prototype._NaNReg = /\D+$/;
+
 /*interface SVGLocatable*/
 /*SVGRect*/   SVGElement.prototype.getBBox = function(){
   var s = new SVGRect();
@@ -319,7 +327,7 @@
    */
   var degis = data.match(/[0-9\-]+/g);
   for (var i=0,degisli=degis.length;i<degisli;i+=2) {
-    var nx = parseInt(degis[i]), ny = parseInt(degis[i+1]);
+    var nx = +(degis[i]), ny = +(degis[i+1]);
     el = el > nx ? nx : el;
     et = et > ny ? ny : et;
     er = er > nx ? er : nx;
@@ -4139,7 +4147,7 @@
       rx = ry = r;
       var tarrect = tar.getBBox();
       var vi = tar.ownerDocument.documentElement.viewport;
-      var el = vi.width, et = vi.height, er = 0, eb = 0;
+      var el = vi.width | 0, et = vi.height | 0, er = 0, eb = 0;
       var units = grad.getAttributeNS(null, "gradientUnits");
       if (!units || units === "objectBoundingBox") {
         //%の場合は小数点に変換(10% -> 0.1)




Sie-announce メーリングリストの案内
Back to archive index