[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Can someone sell Lua 5.2.0 to me please ?
- From: Javier Guerra Giraldez <javier@...>
- Date: Mon, 19 Dec 2011 10:22:38 -0500
On Sun, Dec 18, 2011 at 8:05 PM, Gé Weijers <email@example.com> wrote:
> Even in C++ adding a single character to a string using += can result in
> copying the whole string to a new buffer, an O(n) operation. There are
> tricks to keep the amortized complexity of your string operations from
> getting out of hand, such as doubling the string buffer size when you need
> to reallocate, but a single operations can still be slow.
the point isn't about (in)efficiency, but about semantics. in C++,
the += operator modifies the value, so any variable that points to the
same value will see the modification, regardless of if a new string
has been allocated or not.
In Lua, if a += operator gets accepted, it would have to be _very_
clear if it's a mutating operator (and would have to add the
respective metatable operators) or if it's just sugar for a=a+b
(making the syntax somewhat misleading)