Optimize list lookups a bit
authorunc0rr
Wed, 08 Oct 2008 15:57:35 +0000
changeset 1320 bffc7262e25e
parent 1319 fedaae857a50
child 1321 d7dc4e86201e
Optimize list lookups a bit
QTfrontend/newnetclient.cpp
netserver/HWProto.hs
--- a/QTfrontend/newnetclient.cpp	Wed Oct 08 15:55:23 2008 +0000
+++ b/QTfrontend/newnetclient.cpp	Wed Oct 08 15:57:35 2008 +0000
@@ -300,22 +300,6 @@
     return;
   }
 
-  if (lst[0] == "CONFIGURED") {
-    QStringList tmp = lst;
-    tmp.removeFirst();
-    if(tmp.size() < 6)
-    {
-      qWarning("Net: Bad CONFIGURED message");
-      return;
-    }
-    emit seedChanged(tmp[0]);
-    emit mapChanged(tmp[1]);
-    emit themeChanged(tmp[2]);
-    emit initHealthChanged(tmp[3].toUInt());
-    emit turnTimeChanged(tmp[4].toUInt());
-    emit fortsModeChanged(tmp[5].toInt() != 0);
-    return;
-  }
 
   if(lst[0]=="TEAM_ACCEPTED") {
     if(lst.size() < 3)
--- a/netserver/HWProto.hs	Wed Oct 08 15:55:23 2008 +0000
+++ b/netserver/HWProto.hs	Wed Oct 08 15:57:35 2008 +0000
@@ -4,7 +4,7 @@
 import Data.List
 import Data.Word
 import Miscutils
-import Maybe (fromMaybe, fromJust)
+import Maybe
 import qualified Data.Map as Map
 
 answerBadCmd = [(clientOnly, ["ERROR", "Bad command, state or incorrect parameter"])]
@@ -61,7 +61,7 @@
 	else
 		(modifyClient client{nick = newNick}, noChangeRooms, answerNick newNick)
 	where
-		haveSameNick = not . null $ filter (\cl -> newNick == nick cl) clients
+		haveSameNick = isJust $ find (\cl -> newNick == nick cl) clients
 
 handleCmd_noInfo client _ _ ["PROTO", protoNum] =
 	if protocol client > 0 then
@@ -87,7 +87,7 @@
 	else
 		(modifyClient client{room = newRoom, isMaster = True}, addRoom (RoomInfo newRoom roomPassword (protocol client) [] Map.empty), answerJoined $ nick client)
 	where
-		haveSameRoom = not . null $ filter (\room -> newRoom == name room) rooms
+		haveSameRoom = isJust $ find (\room -> newRoom == name room) rooms
 
 handleCmd_noRoom client clients rooms ["CREATE", newRoom] =
 	handleCmd_noRoom client clients rooms ["CREATE", newRoom, ""]
@@ -100,7 +100,7 @@
 	else
 		(modifyClient client{room = roomName}, noChangeRooms, (answerJoined $ nick client) ++ answerNicks ++ answerFullConfig joinRoom)
 	where
-		noSuchRoom = null $ filter (\room -> roomName == name room) rooms
+		noSuchRoom = isNothing $ find (\room -> roomName == name room) rooms
 		answerNicks = [(clientOnly, ["JOINED"] ++ (map nick $ filter (\ci -> room ci == roomName) clients))]
 		joinRoom = roomByName roomName rooms