(
&self,
f: impl FnOnce(&mut ReadContext) -> Result<R, Error>,
)
| 1063 | /// Uses fast path caching for O(1) access when using the same Fory instance repeatedly. |
| 1064 | #[inline(always)] |
| 1065 | fn with_read_context<R>( |
| 1066 | &self, |
| 1067 | f: impl FnOnce(&mut ReadContext) -> Result<R, Error>, |
| 1068 | ) -> Result<R, Error> { |
| 1069 | // SAFETY: Thread-local storage is only accessed from the current thread. |
| 1070 | // We use UnsafeCell to avoid RefCell's runtime borrow checking overhead. |
| 1071 | // The closure `f` does not recursively call with_read_context, so there's no aliasing. |
| 1072 | READ_CONTEXTS.with(|cache| { |
| 1073 | let cache = unsafe { &mut *cache.get() }; |
| 1074 | let id = self.id; |
| 1075 | |
| 1076 | let context = cache.get_or_insert_result(id, || { |
| 1077 | // Only fetch type resolver when creating a new context |
| 1078 | let type_resolver = self.get_final_type_resolver()?; |
| 1079 | Ok(Box::new(ReadContext::new( |
| 1080 | type_resolver.clone(), |
| 1081 | self.config.clone(), |
| 1082 | ))) |
| 1083 | })?; |
| 1084 | f(context) |
| 1085 | }) |
| 1086 | } |
| 1087 | |
| 1088 | #[inline(always)] |
| 1089 | fn deserialize_with_context<T: Serializer + ForyDefault>( |
no test coverage detected