Use hash instead of array.
authorKoichi KAMICHI <kamichi@fonts.jp>
Wed, 23 Feb 2011 05:30:56 +0000 (05:30 +0000)
committerKoichi KAMICHI <kamichi@fonts.jp>
Wed, 23 Feb 2011 05:30:56 +0000 (05:30 +0000)
engine/buhin.js

index f1cd8ba..3fa0442 100755 (executable)
@@ -1,38 +1,21 @@
 function Buhin(number){\r
   // method\r
-  function push(name, data){ // void\r
-    var temp = new Object();\r
-    temp.name = name;\r
-    temp.data = data;\r
-    this.array.push(temp);\r
-  }\r
-  Buhin.prototype.push = push;\r
-  \r
   function set(name, data){ // void\r
-    var temp = new Object();\r
-    temp.name = name;\r
-    temp.data = data;\r
-    for(var i = 0; i < this.array.length; i++){\r
-      if(this.array[i].name == name){\r
-        this.array.splice(i, 1);\r
-      }\r
-    }\r
-    this.array.push(temp);\r
+    this.hash[name] = data;\r
   }\r
+  Buhin.prototype.push = set;\r
   Buhin.prototype.set = set;\r
   \r
   function search(name){ // string\r
-    for(var i = 0; i < this.array.length; i++){\r
-      if(this.array[i].name == name){\r
-        return this.array[i].data;\r
-      }\r
+    if(this.hash[name]){\r
+      return this.hash[name];\r
     }\r
     return ""; // no data\r
   }\r
   Buhin.prototype.search = search;\r
   \r
   // property\r
-  this.array = new Array();\r
+  this.hash = {};\r
   \r
   // initialize\r
   // no operation\r