Commit 649ae0e
Skip encoder inspection on ToPython when no encoders registered
Extends the previous TryEncode optimization to the EncodableByUser gate in
Converter.ToPython. Previously every value conversion ran Type.GetTypeCode
plus enum/type checks before TryEncode could cheaply short-circuit on the
cached "no encoders" flag. EncodableByUser now checks HasEncoders first and
returns false immediately when none are registered (the common case), so the
entire encoder branch - including the type inspection - is skipped on the hot
per-value conversion path.
Also drop a redundant value.GetType() in EncodableByUser: the local already
holds value.GetType() at every call site, so compare against it directly.
Behavior is unchanged: with no encoders the branch was always going to fall
through; with encoders, HasEncoders is true so the gate reduces to the
previous EncodableByUser check.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent a6f616f commit 649ae0e
2 files changed
Lines changed: 16 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
741 | 741 | | |
742 | 742 | | |
743 | 743 | | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
744 | 753 | | |
745 | 754 | | |
746 | 755 | | |
747 | | - | |
| 756 | + | |
748 | 757 | | |
749 | 758 | | |
750 | 759 | | |
| |||
0 commit comments