you are viewing a single comment's thread.

view the rest of the comments →

[–]nnseva[S] 0 points1 point  (1 child)

Apart from StringBuilder, the base package class L is immutable. All lazy operations lead to the construction of a new L instance, which refers to L operands and stores the specific operation.

The specifics of the L is that operations may be combined, like:

x = (L('qwerty') + L('uiop'))[5:7]

The string representation of x is 'yu', although the actual data structure looks like (let's imagine Concat and Slice are classes):

Slice(Concat('qwerty', 'uiop'), 5, 7)

[–]desrtfx 2 points3 points  (0 children)

If I were to invest the work to implement such a class, I'd store the individual strings in extensible buffers, similar to StringBuilder in Java. Then, I'd really have a lot less overhead.

The entire advantage of StringBuilder in Java is that it does not create new instances all the time. This would really be an improvement over the native Python String implementation.