Commit 9205e32b authored by Stefan Behnel's avatar Stefan Behnel

Refactor some duplicate code in TypeSlots.py.

parent 139bd745
...@@ -250,14 +250,17 @@ class SlotDescriptor(object): ...@@ -250,14 +250,17 @@ class SlotDescriptor(object):
def generate_dynamic_init_code(self, scope, code): def generate_dynamic_init_code(self, scope, code):
if self.is_initialised_dynamically: if self.is_initialised_dynamically:
value = self.slot_code(scope) self.generate_set_slot_code(
if value != "0": self.slot_code(scope), scope, code)
def generate_set_slot_code(self, value, scope, code):
if value == "0":
return
code.putln("%s.%s = %s;" % ( code.putln("%s.%s = %s;" % (
scope.parent_type.typeobj_cname, scope.parent_type.typeobj_cname,
self.slot_name, self.slot_name,
value value,
) ))
)
class FixedSlot(SlotDescriptor): class FixedSlot(SlotDescriptor):
...@@ -408,10 +411,7 @@ class ConstructorSlot(InternalMethodSlot): ...@@ -408,10 +411,7 @@ class ConstructorSlot(InternalMethodSlot):
else: else:
return return
code.putln("%s.%s = %s;" % ( self.generate_set_slot_code(src, scope, code)
scope.parent_type.typeobj_cname,
self.slot_name,
src))
class SyntheticSlot(InternalMethodSlot): class SyntheticSlot(InternalMethodSlot):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment