bevy/crates/bevy_reflect/src
Nicola Papale 0bd4ea7ced
Provide getters for fields of ReflectFromPtr (#9748)
# Objective

The reasoning is similar to #8687.

I'm building a dynamic query. Currently, I store the ReflectFromPtr in
my dynamic `Fetch` type.

[See relevant
code](97ba68ae1e/src/fetches.rs (L14-L17))

However, `ReflectFromPtr` is:

- 16 bytes for TypeId
- 8 bytes for the non-mutable function pointer
- 8 bytes for the mutable function pointer

It's a lot, it adds 32 bytes to my base `Fetch` which is only
`ComponendId` (8 bytes) for a total of 40 bytes.

I only need one function per fetch, reducing the total dynamic fetch
size to 16 bytes.

Since I'm querying the components by the ComponendId associated with the
function pointer I'm using, I don't need the TypeId, it's a redundant
check.

In fact, I've difficulties coming up with situations where checking the
TypeId beforehand is relevant. So to me, if ReflectFromPtr makes sense
as a public API, exposing the function pointers also makes sense.

## Solution

- Make the fields public through methods.

---

## Changelog

- Add `from_ptr` and `from_ptr_mut` methods to `ReflectFromPtr` to
access the underlying function pointers
- `ReflectFromPtr::as_reflect_ptr` is now `ReflectFromPtr::as_reflect`
- `ReflectFromPtr::as_reflect_ptr_mut` is now
`ReflectFromPtr::as_reflect_mut`

## Migration guide

- `ReflectFromPtr::as_reflect_ptr` is now `ReflectFromPtr::as_reflect`
- `ReflectFromPtr::as_reflect_ptr_mut` is now
`ReflectFromPtr::as_reflect_mut`
2023-09-18 13:41:51 +00:00
..
enums bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
impls Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
path Fix some nightly warnings (#9672) 2023-09-02 18:35:06 +00:00
serde Remove useless single tuples and trailing commas (#9720) 2023-09-08 21:46:54 +00:00
array.rs Fix typos throughout the project (#9090) 2023-07-10 00:11:51 +00:00
fields.rs bevy_reflect: Reflect doc comments (#6234) 2022-10-18 13:49:57 +00:00
from_reflect.rs Fix typos throughout the project (#9090) 2023-07-10 00:11:51 +00:00
lib.rs Make it so ParsedPath can be passed to GetPath (#9373) 2023-08-25 14:32:41 +00:00
list.rs Fix typos throughout the project (#9090) 2023-07-10 00:11:51 +00:00
map.rs Fix CI for Rust 1.72 (#9562) 2023-08-25 12:34:24 +00:00
reflect.rs Reflect now requires DynamicTypePath. Remove Reflect::get_type_path() (#8764) 2023-06-06 17:23:58 +00:00
std_traits.rs fix nightly clippy warnings (#6395) 2022-10-28 21:03:01 +00:00
struct_trait.rs Fix CI for Rust 1.72 (#9562) 2023-08-25 12:34:24 +00:00
tuple_struct.rs Reflect now requires DynamicTypePath. Remove Reflect::get_type_path() (#8764) 2023-06-06 17:23:58 +00:00
tuple.rs Reflect now requires DynamicTypePath. Remove Reflect::get_type_path() (#8764) 2023-06-06 17:23:58 +00:00
type_info.rs Reflect now requires DynamicTypePath. Remove Reflect::get_type_path() (#8764) 2023-06-06 17:23:58 +00:00
type_path.rs Fix typos throughout the project (#9090) 2023-07-10 00:11:51 +00:00
type_registry.rs Provide getters for fields of ReflectFromPtr (#9748) 2023-09-18 13:41:51 +00:00
type_uuid_impl.rs implement TypeUuid for primitives and fix multiple-parameter generics having the same TypeUuid (#6633) 2023-02-16 17:09:44 +00:00
type_uuid.rs implement TypeUuid for primitives and fix multiple-parameter generics having the same TypeUuid (#6633) 2023-02-16 17:09:44 +00:00
utility.rs Fix typos throughout the project (#9090) 2023-07-10 00:11:51 +00:00