Suggestions for the usage style of constant strings in source code. #4373
lph993
started this conversation in
Engine Core
Replies: 1 comment
-
Related to #2152. Godot already has a StringName which performs string interning, but it's not used everywhere it could be. However, there is a cost to creating new StringNames, so it needs to be used enough times to be worth it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Well, it is recommended to create a header file to manage common constant strings, and to specify a corresponding naming protocol, which is convenient for use and comparison, and can improve development efficiency and program performance a little. Listed in this place:
This is required when calling:
Code is for example only.
If the string is written in a wrong place, it is necessary to find its exact position, copying or even finding it is very troublesome, and it needs to be modified. In addition, if the string is too long, it will affect performance and take up space, after all, it is a comparison of the content of the string. If you declare a constant string, you only need to compare the address of the string, or you can compare the address first and then compare the content if it is different to achieve compatible writing. Doing this should give a slight performance boost. In addition, you can call this header file in other C++ files, and you can also do some extension functions on the header file.
(This text was translated from the web.)
Beta Was this translation helpful? Give feedback.
All reactions