-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
str1 + str2 + str2
should be optimized
#276
Comments
Have you thought about python style string formatting "hello {} {}".format(firstName, lastName) or something similar? Also for joining and splitting arrays ",".join(array) or array.split(",") ? |
You've answered your question correctly :)
|
Is it now |
@gslicer the first one |
That seems again inconsistent with the Array notation where it is stated (according to docs): So I would expect string (which is a [byte|rune]-Array to support the same notation - why not let + be pure mathematical? When there was something I liked in C++ it was the "<<" operator on iostreams (which were basically byte-streams or var-length strings ;) |
|
I'm sorry @medvednikov but in current implementation string looks like an array to me (and you even called the variable representing a string "arr" which resambles Array):
My point is, + could be used only for arithmetic operations, and << for concatenation (of any kind) - this would be more streamlined with the "simple" and "do similar stuff with similar syntax" approach, don't you think? |
No, it's not an array. String is an immutable struct with a pointer to string data, len, and capacity integers. In this function |
By the way thanks for referring to this function, it needs to be updated :) |
Things like that may be nice, but not only it's additional complexity in the compiler, but also it's not even obvious that there are such optimizations, so it's one more random thing to learn. |
Related: #22188 |
Things like this should be simple in the new compiler. The IL will make optimizations much simpler. |
Concatenating multiple strings should always result in only one allocation.
The text was updated successfully, but these errors were encountered: