lua-users home
lua-l archive

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


> There's no reason you can't write print(myTable['(╯°□°)╯︵ ┻━┻']), though.

As I pointed out in a previous message, once you lose your mind, there
is no limit on what you can think (or do)... (BTW, this key is still
shorter than 40 bytes ;)


> >  > why the compiler doesn't pre-hash string literals in Lua source?
> >
> > It does in the lexer. See luaX_newstring in the source. It calls
> > luaS_newlstr which interns short strings.
> >
> >
> Would interning longer strings in the source code present any problems?

It is a tradeoff between fast comparsions (if the string is used as a
table key) versus wasted time computing hashes and interning the string
(if it is not). Think about a program that generates many non-key strings
in this middle range (e.g., reading lines of a file). Of course, the
longer the string, the more expensive it is to compute its hash and to
internalize it.

It would be great to have some real data about that. Many people in this
list can cooperate. How does this limit affect real programs? (Just
change LUAI_MAXSHORTLEN in luaconf.h and try it.)

-- Roberto