Skip to content

Optimize Endianness Handling in ctypes Module #124351

@Harikrishna-Srinivasan

Description

@Harikrishna-Srinivasan

Feature or enhancement

Proposal:

  1. Global variable _OTHER_ENDIAN, in the _other_endian function to check for endianness but declared at the module level, leading to potential side effects.

Redundant Type Checks slows down recursion:

if hasattr(typ, _OTHER_ENDIAN):
if isinstance(typ, _array_type):
if issubclass(typ, (Structure, Union)):

Issue: Multiple checks on each call can be inefficient, especially if called frequently.

  1. In the setattr method of the _swapped_meta class,
for desc in value:
    fields.append((name, _other_endian(typ)) + rest)

Issue: Always creates a new list, even when no modifications are needed, which adds overhead.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions