[Sie-announce] SIEコード [2690] getFloatValueメソッドの高速化

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2011年 5月 18日 (水) 23:24:22 JST


Revision: 2690
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=2690
Author:   dhrname
Date:     2011-05-18 23:24:22 +0900 (Wed, 18 May 2011)

Log Message:
-----------
getFloatValueメソッドの高速化

Modified Paths:
--------------
    branches/07x/078/org/w3c/dom/css.js

Modified: branches/07x/078/org/w3c/dom/css.js
===================================================================
--- branches/07x/078/org/w3c/dom/css.js	2011-05-16 12:56:36 UTC (rev 2689)
+++ branches/07x/078/org/w3c/dom/css.js	2011-05-18 14:24:22 UTC (rev 2690)
@@ -432,44 +432,41 @@
   /*getFloatValueメソッド
    *別の単位に変換可能。
    */
-  this._regD = /\D+$/;
   this._regd = /[\d\.]+/;
   /*float*/ this.getFloatValue = function(/*short*/ unitType) {
     if ((/*CSSPrimitiveValue.CSS_UNKNOWN*/ 0 >= unitType) && (unitType >= /*CSSPrimitiveValue.CSS_STRING*/ 19)) { //浮動小数点数単位型をサポートしないCSS単位である場合
       throw new DOMException(DOMException.INVALID_ACCESS_ERR);
     }
-    var n = this.cssText.match(this._regD),
+    var tc = this.cssText,
+        n = tc.charAt(tc.length-1),
         type = 0,
-        s = +(this.cssText.match(this._regd));
+        s = +(tc.match(this._regd));
     s = isNaN(s) ? 0 : s;
-    if (!!n) {
-      n = n[0];
-    }
-    if (!n) {
+    if (n >= "0" && n <= "9") {
       type = /*CSSPrimitiveValue.CSS_NUMBER*/ 1;
     } else if (n === "%") {
       s *= this._percent;
       type = /*CSSPrimitiveValue.CSS_PERCENTAGE*/ 2;
-    } else if (n === "em") {
+    } else if ((n === "m") && (tc.charAt(tc.length-2) === "e")) {
       s *= this._empercent;
       type = /*CSSPrimitiveValue.CSS_EMS*/ 3;
-    } else if (n === "ex") {
+    } else if ((n === "x") && (tc.charAt(tc.length-2) === "e")) {
       type = /*CSSPrimitiveValue.CSS_EXS*/ 4;
-    } else if (n === "px") {
+    } else if ((n === "x") && (tc.charAt(tc.length-2) === "p")) {
       type = /*CSSPrimitiveValue.CSS_PX*/ 5;
-    } else if (n === "cm") {
+    } else if ((n === "m") && (tc.charAt(tc.length-2) === "c")) {
       type = /*CSSPrimitiveValue.CSS_CM*/ 6;
-    } else if (n === "mm") {
+    } else if ((n === "m") && (tc.charAt(tc.length-2) === "m")) {
       type = /*CSSPrimitiveValue.CSS_MM*/ 7;
-    } else if (n === "in") {
+    } else if (n === "n") {
       type = /*CSSPrimitiveValue.CSS_IN*/ 8;
-    } else if (n === "pt") {
+    } else if (n === "t") {
       type = /*CSSPrimitiveValue.CSS_PT*/ 9;
-    } else if (n === "pc") {
+    } else if (n === "c") {
       type = /*CSSPrimitiveValue.CSS_PC*/ 10;
     }
     this._value = s * this._n[type-1];  //値はあらかじめ、利用しやすいように変換しておく
-    n = type = s = null;
+    tc = n = type = s = null;
     return (this._value / this._n[unitType-1]);
   };
   /*void*/ this.setStringValue = function(/*short*/ stringType, /*string*/ stringValue) {




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