Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2004:
[Freeciv-Dev] (PR#8190) Make packets_gen.c smaller
Home

[Freeciv-Dev] (PR#8190) Make packets_gen.c smaller

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8190) Make packets_gen.c smaller
From: "Raimar Falke" <i-freeciv-lists@xxxxxxxxxxxxx>
Date: Thu, 18 Mar 2004 12:52:05 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8190 >


The attached patch merges all hash and cmp functions for variants
which doesn't have at least one key field.

Compiles size goes down from
23996 lines
 270739       0       0  270739   42193 packets_gen.o
to
23496 lines
 268051       0       0  268051   41713 packets_gen.o

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "The Internet is really just a series of bottlenecks 
  joined by high speed networks."
    -- Sam Wilson

Index: common/generate_packets.py
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/generate_packets.py,v
retrieving revision 1.7
diff -u -u -r1.7 generate_packets.py
--- common/generate_packets.py  15 Jan 2004 11:52:38 -0000      1.7
+++ common/generate_packets.py  18 Mar 2004 20:43:34 -0000
@@ -593,11 +593,13 @@
     # Returns a code fragement which is the implementation of the hash
     # function. The hash function is using all key fields.
     def get_hash(self):
-        intro='''static unsigned int hash_%(name)s(const void *vkey, unsigned 
int num_buckets)
+        if len(self.key_fields)==0:
+            return "#define hash_%(name)s hash_const\n\n"%self.__dict__
+        else:
+            intro='''static unsigned int hash_%(name)s(const void *vkey, 
unsigned int num_buckets)
 {
 '''%self.__dict__
 
-        if len(self.key_fields):
             body='''  const struct %(packet_name)s *key = (const struct 
%(packet_name)s *) vkey;
 
 '''%self.__dict__
@@ -610,20 +612,20 @@
             else:
                 assert 0
             body=body+('  return ((%s) %% num_buckets);\n'%a)
-        else:
-            body="  return 0;\n"
-        extro="}\n\n"
-        return intro+body+extro
+            extro="}\n\n"
+            return intro+body+extro
 
     # Returns a code fragement which is the implementation of the cmp
     # function. The cmp function is using all key fields. The cmp
     # function is used for the hash table.    
     def get_cmp(self):
-        intro='''static int cmp_%(name)s(const void *vkey1, const void *vkey2)
+        if len(self.key_fields)==0:
+            return "#define cmp_%(name)s cmp_const\n\n"%self.__dict__
+        else:
+            intro='''static int cmp_%(name)s(const void *vkey1, const void 
*vkey2)
 {
 '''%self.__dict__
-        body=""
-        if len(self.key_fields):
+            body=""
             body=body+'''  const struct %(packet_name)s *key1 = (const struct 
%(packet_name)s *) vkey1;
   const struct %(packet_name)s *key2 = (const struct %(packet_name)s *) vkey2;
   int diff;
@@ -636,8 +638,8 @@
   }
 
 '''%(field.name,field.name)
-        extro="  return 0;\n}\n\n"
-        return intro+body+extro
+            extro="  return 0;\n}\n\n"
+            return intro+body+extro
 
     # Returns a code fragement which is the implementation of the send
     # function. This is one of the two real functions. So it is rather
@@ -1396,6 +1398,16 @@
 #include "support.h"
 
 #include "packets.h"
+
+static unsigned int hash_const(const void *vkey, unsigned int num_buckets)
+{
+  return 0;
+}
+
+static int cmp_const(const void *vkey1, const void *vkey2)
+{
+  return 0;
+}
 
 ''')
 

[Prev in Thread] Current Thread [Next in Thread]