Skip to content

Commit 6e35fe9

Browse files
committed
optimize code
1 parent 21d83a3 commit 6e35fe9

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/input/input_python.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,17 @@ fn get_ordered_dict_type(py: Python<'_>) -> &Bound<'_, PyType> {
6262
.bind(py)
6363
}
6464

65-
// Ultra-fast OrderedDict detection with multiple optimization layers
6665
fn check_if_ordered_dict(obj: &Bound<'_, PyAny>) -> bool {
67-
// FASTEST PATH: Check if it's exact PyDict first - skip everything for regular dicts
6866
if obj.is_exact_instance_of::<PyDict>() {
69-
return false; // Regular dict - absolutely not OrderedDict
67+
return false;
7068
}
7169

72-
// FAST PATH: Quick type name check - avoid Python import if possible
7370
if let Ok(type_name) = obj.get_type().name() {
7471
if type_name.to_string() != "OrderedDict" {
75-
return false; // Not OrderedDict based on name
72+
return false;
7673
}
7774
}
7875

79-
// SLOW PATH: Only for actual OrderedDict objects - expensive type lookup
8076
let ordered_dict_type = get_ordered_dict_type(obj.py());
8177
obj.is_instance(ordered_dict_type).unwrap_or(false)
8278
}
@@ -432,6 +428,7 @@ impl<'py> Input<'py> for Bound<'py, PyAny> {
432428
}
433429

434430
fn lax_dict<'a>(&'a self) -> ValResult<GenericPyMapping<'a, 'py>> {
431+
435432
if check_if_ordered_dict(self) {
436433
// OrderedDict is a subclass of dict, but we want to treat it as a mapping to preserve order
437434
if let Ok(mapping) = self.downcast::<PyMapping>() {

0 commit comments

Comments
 (0)