Precompute the flag index on the generated code

This commit is contained in:
Lonami Exo 2017-09-29 13:03:35 +02:00
parent 76d14b2dd9
commit a4fa652d35

View File

@ -472,8 +472,8 @@ class TLGenerator:
elif arg.flag_indicator:
# Calculate the flags with those items which are not None
builder.write("struct.pack('<I', {})".format(
' | '.join('(1 << {} if {} else 0)'.format(
flag.flag_index, 'self.{}'.format(flag.name)
' | '.join('({} if {} else 0)'.format(
1 << flag.flag_index, 'self.{}'.format(flag.name)
) for flag in args if flag.is_flag)
))
@ -550,8 +550,8 @@ class TLGenerator:
was_flag = False
if arg.is_flag:
was_flag = True
builder.writeln('if (flags & (1 << {})) != 0:'.format(
arg.flag_index
builder.writeln('if flags & {}:'.format(
1 << arg.flag_index
))
# Temporary disable .is_flag not to enter this if
# again when calling the method recursively