Change sceneLoaded.name comparison against m_SceneToLoad#3656
Change sceneLoaded.name comparison against m_SceneToLoad#3656GabrielBigardi wants to merge 1 commit intoUnity-Technologies:developfrom
Conversation
Using .ToLower() to compare strings is very inefficient as it allocates a new string. Using string.Equals with StringComparison.OrdinalIgnoreCase is not only a lot faster but also handles some problems that may happen on different cultures, as shown in this video from "Bald. Bearded. Builder.": https://www.youtube.com/watch?v=DNzAoLwXLzc
EmandM
left a comment
There was a problem hiding this comment.
Hi! Thanks for this submission.
Out of interest, which issue did you see that needs this fix?
I ask as this script is inside our test project in a path that is unlikely to be called often. Is there a reason this optimization is needed here?
Hello! Apart from being a way faster way of comparing these strings (which may helps a lot on older/weaker devices), it also fix a problem that may be caused by different cultures in C#. Using .ToLower() for comparison won't work for Turkish and a few other countries. If the culture is set to turkish, sceneLoaded.name is "IndieGame" and m_SceneToLoad is "indiegame" for example this check will fail. |
|
Thanks for the reproduction! Just for our knowledge, how are you using the NGO test project in your environment? |
|
Closing this PR as this issue is only within our testproject which we don't expect to be used in different cultures. If there is a usage pattern that requires testproject within different cultures then we can revisit this fix at this time. |
Purpose of this PR
Using .ToLower() to compare strings is very inefficient as it allocates a new string. Using string.Equals with StringComparison.OrdinalIgnoreCase is not only a lot faster but also handles some problems that may happen on different cultures, as shown in this video from "Bald. Bearded. Builder.": https://www.youtube.com/watch?v=DNzAoLwXLzc
Changelog