Skip to content

Use a value -> member map for decoding ASN.1 value sets#14965

Merged
reaperhulk merged 3 commits into
mainfrom
claude/kind-hopper-O3jQe
Jun 7, 2026
Merged

Use a value -> member map for decoding ASN.1 value sets#14965
reaperhulk merged 3 commits into
mainfrom
claude/kind-hopper-O3jQe

Conversation

@alex
Copy link
Copy Markdown
Member

@alex alex commented Jun 7, 2026

Resolves the performance TODO from #14962: value set decoding did a linear scan over the enum members to map the decoded value back to a member.

Type::ValueSet now stores a value -> member map (a PyDict), built once when the class is decorated, and decoding is a single O(1) dict lookup. This is possible now that the ASN.1 wrapper types implement __hash__ (#14963).

As a consequence, value set member values must be hashable: an enum whose member values implement __eq__ but not __hash__ (e.g. Null) now raises TypeError at decoration time.

https://claude.ai/code/session_01FrUdGjs6fKGSQ6E6WQPGB1


Generated by Claude Code

claude added 3 commits June 7, 2026 01:19
Replaces the linear scan over enum members in value set decoding with
an O(1) lookup in a value -> member map, built once when the class is
registered and stored in Type::ValueSet. This is now possible because
the ASN.1 wrapper types implement __hash__ (#14963).

Member values that implement __eq__ but not __hash__ (e.g. Null) can't
be used as dict keys; for those the map is None and decoding falls
back to the previous linear scan, preserving behavior.

https://claude.ai/code/session_01FrUdGjs6fKGSQ6E6WQPGB1
Per review: value set member values must be hashable. The value ->
member map is now built unconditionally at registration time, so an
enum with unhashable member values (e.g. Null) raises TypeError when
decorated, and decoding is always an O(1) map lookup.

https://claude.ai/code/session_01FrUdGjs6fKGSQ6E6WQPGB1
- Use a {} literal for the value map in test_fields_of_variant_type
  (the annotation stays: mypy can't infer the type of an empty literal)
- Drop test_fail_unhashable_member_values

https://claude.ai/code/session_01FrUdGjs6fKGSQ6E6WQPGB1
@reaperhulk reaperhulk enabled auto-merge (squash) June 7, 2026 04:11
@reaperhulk reaperhulk merged commit 9ec75b4 into main Jun 7, 2026
64 checks passed
@reaperhulk reaperhulk deleted the claude/kind-hopper-O3jQe branch June 7, 2026 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants