Author: pepeto Date: Thu Dec 18 00:56:40 2014 New Revision: 27339 URL: http://svn.gna.org/viewcvs/freeciv?rev=27339&view=rev Log: Replace switch statement by an array of booleans in packet_has_game_info_flag().
See gna patch #5568 Modified: trunk/common/generate_packets.py Modified: trunk/common/generate_packets.py URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/generate_packets.py?rev=27339&r1=27338&r2=27339&view=diff ============================================================================== --- trunk/common/generate_packets.py (original) +++ trunk/common/generate_packets.py Thu Dec 18 00:56:40 2014 @@ -1370,19 +1370,29 @@ def get_packet_has_game_info_flag(packets): intro='''bool packet_has_game_info_flag(enum packet_type type) { - switch (type) { - -''' + static const bool flag[PACKET_LAST] = { +''' + + mapping={} + for p in packets: + mapping[p.type_number]=p + sorted=list(mapping.keys()) + sorted.sort() + + last=-1 body="" - for p in packets: - body=body+' case %(type)s:\n'%p.__dict__ - if p.is_info != "game": - body=body+' return FALSE;\n\n' - else: - body=body+' return TRUE;\n\n' - extro=''' default: - return FALSE; - } + for n in sorted: + for i in range(last + 1, n): + body=body+' FALSE,\n' + if mapping[n].is_info!="game": + body=body+' FALSE, /* %s */\n'%mapping[n].type + else: + body=body+' TRUE, /* %s */\n'%mapping[n].type + last=n + + extro=''' }; + + return (type >= 0 && type < PACKET_LAST ? flag[type] : FALSE); } ''' _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits