[Sie-announce] SIEコード [1550] STPathオブジェクトの高速化

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 1月 7日 (木) 21:09:05 JST


Revision: 1550
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1550
Author:   dhrname
Date:     2010-01-07 21:09:05 +0900 (Thu, 07 Jan 2010)

Log Message:
-----------
STPathオブジェクトの高速化

Modified Paths:
--------------
    branches/05x/058/sie.js

Modified: branches/05x/058/sie.js
===================================================================
--- branches/05x/058/sie.js	2010-01-06 14:21:14 UTC (rev 1549)
+++ branches/05x/058/sie.js	2010-01-07 12:09:05 UTC (rev 1550)
@@ -605,10 +605,34 @@
   var a =  /^\],/,
       b = /\s*$/,
       c = /[\s,]{2,}|\s/g,
-      isCorQ = {
-        "c" : 1,
-        "q" : 1
-      };
+  isCorQ = {
+    c : 1,
+    q : 1
+  },
+  isZ = {
+    z : 1
+  },
+  isM = {
+    m : 1
+  },
+  isA = {
+    a : 1
+  },
+  isQ = {
+    q : 1
+  },
+  isH = {
+    h : 1
+  },
+  isV = {
+    v : 1
+  },
+  isS = {
+    s : 1
+  },
+  isT = {
+    t : 1
+  };
 STPath.prototype.set = function( /*float*/ w, /*float*/ h) {
   var dat = "", _isCorQ = isCorQ, _parseInt = parseInt, _eval = eval;
   try {
@@ -629,10 +653,10 @@
       var F = D[i];
       var com = F[0].toLowerCase(); //F[0]の値はコマンド文字
       var rel = (com === F[0]);     //相対座標のコマンドならtrue
-      if (com === "z") {
+      if (isZ[com]) {
         F = ["x"];
         x = x0; y = y0;
-      } else if (com === "a") { //ArcTo
+      } else if (isA[com]) { //ArcTo
         F[0] = "c";
         preCom = com;
         var relx = 0, rely = 0;
@@ -654,16 +678,24 @@
         if (rel) {
           rx = ry = 0;
         }
-        switch (com) { //ここはif文ではなくて、switch文で処理する必要がある。
-          case "h": F = ["l", F[F.length-1], ry];
-          break;
-          case "v": F = ["l", rx, F[F.length-1]];
-          break;
-          case "s": F[0] = "c"; if (preCom !== "c") {dx = dy = 0;} F = NAIBU.nst(6, F, rx + dx, ry + dy);
-          break;
-          case "t": F[0] = "q"; if (preCom !== "q") {dx = dy = 0;} F = NAIBU.nst(4, F, rx + dx, ry + dy);
-          break;
-          default:  F[0] = com; //"M", "L", "C", "Q" は小文字に変換
+        if(isH[com]) {
+          F = ["l", F[F.length-1], ry];
+        } else if(isV[com]) {
+          F = ["l", rx, F[F.length-1]];
+        } else if(isS[com]) {
+          F[0] = "c";
+          if (preCom !== "c") {
+            dx = dy = 0;
+          }
+          F = NAIBU.nst(6, F, rx + dx, ry + dy);
+        } else if(isT[com]) {
+          F[0] = "q";
+          if (preCom !== "q") {
+            dx = dy = 0;
+          }
+          F = NAIBU.nst(4, F, rx + dx, ry + dy);
+        } else {
+          F[0] = com; //"M", "L", "C", "Q" は小文字に変換
         }
         if (rel) {
           F = NAIBU.reltoabs(x, y, F); //絶対座標に変換
@@ -674,10 +706,10 @@
           dx = F[Fli-2] - F[Fli-4];
           dy = F[Fli-1] - F[Fli-3];
         }
-        if (com === "q") {
+        if (isQ[com]) {
           F = NAIBU.qtoc(x, y, F); //二次ベジェは三次ベジェに変換
         }
-        if (com === "m") {
+        if (isM[com]) {
           x0 = F[1]; y0 = F[2]; //subpath の始点を記憶
         }
         var Fli = F.length;
@@ -690,7 +722,7 @@
           F[j]   = _x;
           F[j+1] = _y;
         }
-        if (com === "m" && Fli > 3) { //MoveToが複数の座標ならば、2番目以降の座標ペアをLineToとして処理
+        if (isM[com] && Fli > 3) { //MoveToが複数の座標ならば、2番目以降の座標ペアをLineToとして処理
           F.splice(3, 0, "l");
         }
       }
@@ -2630,10 +2662,12 @@
   obst.width = regwv+ "px";
   obst.height = reghv+ "px";
   ob.coordsize = regwv  +" "+  reghv;
+  var dew = new Date();
   var STdocument = new SVGtoVML(obc, obwidth, obheight, regw, regh);
   obj.parentNode.insertBefore(ob, obj);
   STdocument.read(ob);
   STdocument.set(ob);
+  alert((new Date()).getTime() - dew.getTime());
   STdocument = obw = obh = regw = regh = null;
   NAIBU.PaintColor.prototype.cache = {}; //キャッシュの初期化
   if (NAIBU.STObject !== void 0) {NAIBU.STObject.next();}




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