Avoid building a new valid list every encode/decode of an enum, also do a cheaper lookup using a dict rather than a list. Signed-off-by: Weston Andros Adamson <dros@xxxxxxxxxx> --- xdr/xdrgen.py | 12 ++++-------- 1 files changed, 4 insertions(+), 8 deletions(-) diff --git a/xdr/xdrgen.py b/xdr/xdrgen.py index 6d89bfe..963e01b 100755 --- a/xdr/xdrgen.py +++ b/xdr/xdrgen.py @@ -857,21 +857,17 @@ class Info(object): def packenum(self, prefix, data='data'): prefix, data, subheader, array = self._array_pack(prefix, data) - varlist = ["const.%s" % l.id for l in self.body] - check = "%sif self.check_enum and %s not in [%s]:\n" \ + check = "%sif self.check_enum and not const.%s.has_key(%s):\n" \ "%s%sraise XDRError, 'value=%%s not in enum %s' %% %s\n" % \ - (prefix, data, ', '.join(varlist), - prefix, indent, self.id, data) + (prefix, self.id, data, prefix, indent, self.id, data) pack = check + "%sself.pack_int(%s)\n" % (prefix, data) return subheader + pack + array def unpackenum(self, prefix, data='data'): prefix, data, subheader, array = self._array_unpack(prefix, data) - varlist = ["const.%s" % l.id for l in self.body] - check = "%sif self.check_enum and %s not in [%s]:\n" \ + check = "%sif self.check_enum and not const.%s.has_key(%s):\n" \ "%s%sraise XDRError, 'value=%%s not in enum %s' %% %s\n" % \ - (prefix, data, ', '.join(varlist), - prefix, indent, self.id, data) + (prefix, self.id, data, prefix, indent, self.id, data) unpack = "%s%s = self.unpack_int()\n" % (prefix, data) return subheader + unpack + check + array -- 1.7.4.4 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html