There is a recursive function that takes a string as input. It breaks this string into parts and calls itself for each part. This function does not change the input string, only reads it. The function is implemented in Kotlin. To create a substring, the substring function is called:
myFunc(str.substring(begin, length))
There are doubts about the effectiveness of this implementation. A new string is created for each call, although it is enough to pass the beginning and length of the substring in the original string. Does Kotlin have a class for substrings? For example, in the C ++ standard library there is a class std :: string_view, and in Qt there is a class QStringRef. Is there something similar in Kotlin?
Or maybe the String class already optimized and the substring function does not allocate new memory, and the new instance uses the same buffer in memory as the original?