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