Skip to content

Conversation

@mtszkarbowiak
Copy link
Contributor

Currently Dictionary uses buckets to expose data. This means that the key can be changed, potentially ruining the state of the collection.

This is an API breaking change.

HashSet is to be revised in the future.

This one is debatable. It follows modern C++.
This one prohibits annoying casts. It is also important for future context injection and follows STL practice.
Returning const object does not prevent from using mutable by triggering copy constructor.
This one is more stylistic but is consistent with practice of using pre- operations for iterators.
This is a small compilation time optimization by reducing total number of generated types. Should not change runtime behavior.
@mtszkarbowiak mtszkarbowiak force-pushed the fix/dictionary-integrity branch 2 times, most recently from af99ed5 to 89a0410 Compare October 31, 2024 14:44
@mtszkarbowiak mtszkarbowiak force-pushed the fix/dictionary-integrity branch from 89a0410 to 1d56220 Compare October 31, 2024 19:07
@mtszkarbowiak
Copy link
Contributor Author

Can someone help me with changes in the bindings generator?

@mafiesto4 mafiesto4 added the core label Nov 6, 2024
@mafiesto4
Copy link
Member

Can someone help me with changes in the bindings generator?

You can take a look into generated code here: <repo>\Cache\Intermediate\FlaxEditor\Windows\x64\Development\Streaming\Streaming.Bindings.Gen.cpp
C++ codegen is generated by Source\Tools\Flax.Build\Bindings\BindingsGenerator.Cpp.cs. In this case probably ManagedDictionary.h needs to be updated and codegen inside GenerateCpp function that sets Variant from input dictionary data.

@mafiesto4
Copy link
Member

This refactor introduced very large change and potential perf overhead (such as assert on bucket state and function call). Thus I have 2 ideas that maybe could solve this problem but with different approache:
Change Key to be const and use const_cast in Dictionary internals to setup/cleanup value.

I think more important would be addition of ConstIterator for collections that would provide read-only access to both key and value. That would help with const-correctness of foreach loops over dictionaries.

What do you think?

@mtszkarbowiak
Copy link
Contributor Author

I like the idea a lot. I will try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants