]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/irc/ignorecontroller.js
use home-made string hashset/map instead of js default
[irc/quakenet/qwebirc.git] / js / irc / ignorecontroller.js
index 212d3f96e49e2bf3fa917174d12238fc9ec289b4..4f2554548609c40e0ef4fda9c8acd92a1433f8ee 100644 (file)
@@ -1,7 +1,7 @@
 qwebirc.irc.IgnoreController = new Class({\r
   initialize: function(toIRCLower) {\r
     this.toIRCLower = toIRCLower;\r
-    this.ignored = {};\r
+    this.ignored = new QHash();\r
   },\r
   __toHostKey: function(host) {\r
     if(host.indexOf("!") == -1 && host.indexOf("@") == -1)\r
@@ -14,7 +14,7 @@ qwebirc.irc.IgnoreController = new Class({
       return false;\r
 \r
     var hostKey = this.__toHostKey(host);\r
-    this.ignored[hostKey] = [host, new RegExp("^" + RegExp.fromIRCPattern(hostKey) + "$")];\r
+    this.ignored.put(hostKey, [host, new RegExp("^" + RegExp.fromIRCPattern(hostKey) + "$")]);\r
 \r
     return hostKey;\r
   },\r
@@ -23,33 +23,25 @@ qwebirc.irc.IgnoreController = new Class({
       return null;\r
 \r
     var hostKey = this.__toHostKey(host);\r
-    delete this.ignored[hostKey];\r
+    this.ignored.remove(hostKey);\r
 \r
     return hostKey;\r
   },\r
   get: function() {\r
-    var l = [];\r
-    for(var key in this.ignored)\r
-      if(this.ignored.hasOwnProperty(key))\r
-        l.push(this.ignored[key][0]);\r
-    return l;\r
+    return this.ignored.map(function(k, v) {\r
+      return v[0];\r
+    });\r
   },\r
   isIgnored: function(nick, host) {\r
-    if(host === undefined) {\r
-      return this.ignored[this.__toHostKey(nick)] !== undefined;\r
-    }\r
+    if(host === undefined)\r
+      return this.ignored.contains(this.__toHostKey(nick));\r
 \r
     var mask = this.toIRCLower(nick + "!" + host);\r
-    for(var key in this.ignored) {\r
-      if(!this.ignored.hasOwnProperty(key))\r
-        continue;\r
 \r
-      var r = this.ignored[key][1];\r
-      if(mask.match(r)) {\r
-//        console.log(key + " (" + this.ignored[key][0] + ")" + " matched against " + mask);\r
+    return this.ignored.each(function(k, v) {\r
+//      console.log(k + " (" + v[0] + ")" + " matched against " + mask);\r
+      if(mask.match(v[1]))\r
         return true;\r
-      }\r
-    }\r
-    return false;\r
+    }) === true;\r
   }\r
 });
\ No newline at end of file