lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Not currently, but I am embarking on a project which does a massive
> amount of string manipulation, and I was worried that if this could
> potentially be an issue, I may switch to a different language for the
> work.

As lhf explained, the hashing of equal strings has no impact on the
performance of Lua.

However, there is one thing that should be clear: each string in Lua is
a value, not a "buffer". Therefore, the operation "s = s..a" creates a
new string, with size len(s)+len(a). Usually you do not think much about
that, but if you create a large string (something like 100K) piece by
piece, like

  local s = ""
  for l in io.lines() do
    s = s .. l
  end

you may have a bad surprise (see http://www.lua.org/notes/ltn009.html).
(This has nothing to do with the hashing; Java has exactly the same
problem.) In Lua 4.0, you needed some machinery to solve that. In Lua
5.0, the solution is much easier and much faster:

  local t = {}
  for l in ... do
    table.insert(t, l)
  end
  s = table.concat(t)

This code runs as fast as the "usual" code in languages with buffered
strings, such as Perl or Python.

-- Roberto