[Sie-announce] SIEコード [1936] 軽量化のために、Array . concatの使用を控えて、別の方法をとった

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 7月 11日 (日) 22:56:21 JST


Revision: 1936
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1936
Author:   dhrname
Date:     2010-07-11 22:56:21 +0900 (Sun, 11 Jul 2010)

Log Message:
-----------
軽量化のために、Array.concatの使用を控えて、別の方法をとった

Modified Paths:
--------------
    branches/06x/061/org/w3c/core.js
    branches/06x/061/org/w3c/dom/css.js

Modified: branches/06x/061/org/w3c/core.js
===================================================================
--- branches/06x/061/org/w3c/core.js	2010-07-11 13:00:37 UTC (rev 1935)
+++ branches/06x/061/org/w3c/core.js	2010-07-11 13:56:21 UTC (rev 1936)
@@ -605,12 +605,15 @@
       }
       var d = tnoi.getElementsByTagNameNS(namespaceURI, localName);
       if (d) {
-        s = s.concat(d);
+        for (var j=0,dli=d.length;j<dli;++j) {
+          s[s.length] = d[j];
+        }
         n += d.length;
       }
       ns = ln = d = null;
     }
   }
+  tno = i = j = tcli = dli = null;
   if (n === 0) {
     return null; //該当する要素なし
   }

Modified: branches/06x/061/org/w3c/dom/css.js
===================================================================
--- branches/06x/061/org/w3c/dom/css.js	2010-07-11 13:00:37 UTC (rev 1935)
+++ branches/06x/061/org/w3c/dom/css.js	2010-07-11 13:56:21 UTC (rev 1936)
@@ -187,7 +187,7 @@
   this.cssText;
 /*long*/ this.length = 0;
 /*CSSRule*/ this.parentRule = null;
-  this._list = []; //内部のリスト
+  this._list = [[]]; //内部のリスト
   return this;
 };
 CSSStyleDeclaration.prototype = {
@@ -211,35 +211,37 @@
     if (propertyName === ":") { //どんなデータ型でも、文字列に変換する機能をJavaScriptが持つことに注意
       return null;
     }
-    for (var i=0,tli=this._list.length;i<tli;++i) {
-      var ti = this._list[i], tc = ti.cssText;
-      if (tc.indexOf(propertyName) > -1) {            //プロパティ名に合致するCSSValueオブジェクトが見つかった場合
-        if ((propertyName === "fill:") || (propertyName === "stroke:")) {
-          /*fill、strokeプロパティは別途、SVGPaintで処理(JavaScriptでは、型キャストを使えないため)
-           *CSSPrimitiveValueオブジェクトとSVGPaintオブジェクトを最後に置き換える
-           */
-          ti = new SVGPaint();
-          ti.cssText = tc;
-           var paintType = SVGPaint.SVG_PAINTTYPE_UNKNOWN, uri = null, color = null;
-          if (tc.indexOf("none") > -1) {
-            paintType = SVGPaint.SVG_PAINTTYPE_NONE;
-          } else if (tc.indexOf("currentColor") > -1) {
-            paintType = SVGPaint.SVG_PAINTTYPE_CURRENTCOLOR;
-            color = this.getPropertyValue("color");
-          } else {
-            var _urlreg = /url\(#([^)]+)/;
-            if (_urlreg.test(tc)) {                   //fill属性の値がurl(#id)ならば
-              paintType = SVGPaint.SVG_PAINTTYPE_URI;
-              uri = RegExp.$1;
+    for (var j=0,tli=this._list.length;j<tli;++j) {
+      for (var i=0,ili=this._list[j].length;i<ili;++i) {
+        var ti = this._list[j][i], tc = ti.cssText;
+        if (tc.indexOf(propertyName) > -1) {            //プロパティ名に合致するCSSValueオブジェクトが見つかった場合
+          if ((propertyName === "fill:") || (propertyName === "stroke:")) {
+            /*fill、strokeプロパティは別途、SVGPaintで処理(JavaScriptでは、型キャストを使えないため)
+             *CSSPrimitiveValueオブジェクトとSVGPaintオブジェクトを最後に置き換える
+             */
+            ti = new SVGPaint();
+            ti.cssText = tc;
+             var paintType = SVGPaint.SVG_PAINTTYPE_UNKNOWN, uri = null, color = null;
+            if (tc.indexOf("none") > -1) {
+              paintType = SVGPaint.SVG_PAINTTYPE_NONE;
+            } else if (tc.indexOf("currentColor") > -1) {
+              paintType = SVGPaint.SVG_PAINTTYPE_CURRENTCOLOR;
+              color = this.getPropertyValue("color");
             } else {
-              paintType = SVGPaint.SVG_PAINTTYPE_RGBCOLOR;
-              color = tc.substring(tc.indexOf(":")+1, tc.length);
+              var _urlreg = /url\(#([^)]+)/;
+              if (_urlreg.test(tc)) {                   //fill属性の値がurl(#id)ならば
+                paintType = SVGPaint.SVG_PAINTTYPE_URI;
+                uri = RegExp.$1;
+              } else {
+                paintType = SVGPaint.SVG_PAINTTYPE_RGBCOLOR;
+                color = tc.substring(tc.indexOf(":")+1, tc.length);
+              }
             }
+            ti.setPaint(paintType, uri, color, null);
+            this._list[j][i] = ti;
           }
-          ti.setPaint(paintType, uri, color, null);
-          this._list[i] = ti;
+          return ti;
         }
-        return ti;
       }
     }
     return null;
@@ -250,7 +252,7 @@
 /*string*/   removeProperty : function( /*string*/ propertyName) {
     var tg = this.getPropertyCSSValue(propertyName);
     if (tg) {                        //見つかった場合
-      this._list.splice(tg._num,1);  //Arrayのspliceを利用して、リストからCSSValueオブジェクトを排除
+      this._list[0].splice(tg._num,1);  //Arrayのspliceを利用して、リストからCSSValueオブジェクトを排除
       --this.length;
     }
   },
@@ -286,8 +288,8 @@
       ti._priority = priority;
       ti.cssText = cssText;
       //_numプロパティはremovePropertyメソッドで利用する
-      ti._num = this._list.length;
-      this._list[ti._num] = ti;
+      ti._num = this._list[0].length;
+      this._list[0][ti._num] = ti;
       this[propertyName] = 1;
       ++this.length;
     }
@@ -741,22 +743,26 @@
   return this;
 };
 /*CSSStyleDeclaration*/ ViewCSS.prototype.getComputedStyle = function( /*Element*/ elt, /*string*/ pseudoElt) {
-  var s = new CSSStyleDeclaration();
+  var s = new CSSStyleDeclaration(), slist = s._list;
+  slist[0] = elt.style._list[0];
+  slist[1] = elt._attributeStyle._list[0];  //プレゼンテーション属性を結びつける
   //リストを連結することによって、カスケーディングを実現する
   var pelt = elt.parentNode;
   if (pelt) {
-    if (this._cache_ele !== pelt) {                     //キャッシュを更新する
+    if (this._cache_ele !== pelt) {           //キャッシュを更新する
       this._cache = this.getComputedStyle(pelt, pseudoElt);
       this._cache_ele = pelt;
     }
-    var p = this._cache._list;
+    if (!!this._cache) {
+      for (var i=0,dli=this._cache._list.length;i<dli;++i) {
+        slist[slist.length] = this._cache._list[i];
+      }
+      i = dli = null;
+    }
   } else {
-    var p = CSS2Properties._list;     //デフォルト値の設定
+    slist[slist.length] = CSS2Properties._list;             //デフォルト値の設定
   }
-  s._list = s._list.concat(elt.style._list)
-                   .concat(elt._attributeStyle._list)  //プレゼンテーション属性を結びつける
-                   .concat(p);
-  p = null;
+  s._list = slist;
   s._document = elt.ownerDocument;
   return s;
 };




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