Update string constants to avoid global constructors - Option 2 #2694
+19
−13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As part of the work to make adopting MaterialX easier for us and lowering the number of internal patches we have to carry for security and performance reasons, this PR proposes a method we could use to avoid the global constructor/destructor calls for std::string constants.
There are actually two different possible approaches here - the other is in #2693
This PR only applies the change to a single source file
Property.cpp/h, but if/when one of the two options is selected it would be my intention to apply the same pattern at least to the rest ofMaterialXCore, and then eventually elsewhere.I think I prefer the other option, but this uses
const char*instead ofconst std::string, it needs no other core API changes, it needs no other changes asstd::stringhas a constructor that acceptsconst char*. Also some changes were necessary in the Javascript bindings, which I'm not familiar with - hoping experts there can highlight any problems, if they exist.