lua-users home
lua-l archive

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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Olivier Delannoy wrote:
> Can anyone give some explanation on why the OO syntax is quicker for
> string ?
> Whether it is the case for any objects/classes (user data or lua based
> object)  ?

At a rough guess, I'd say it's because object:find() does a single table
lookup (to find the method), but string.find() does two (one to find 'string',
one to find 'find').

If you're really concerned about speed, I'd recommend this:

  local string_find = string.find
  ...
  a = string_find("...")

That way, the string.find function is only looked up once and the result is
cached in a local variable (which is fast).

- --
┌── dg@cowlark.com ─── http://www.cowlark.com ───────────────────
│ "Parents let children ride bicycles on the street. But parents do not
│ allow children to hear vulgar words. Therefore we can deduce that cursing
│ is more dangerous than being hit by a car." --- Scott Adams
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGPyNdf9E0noFvlzgRAv92AJ0TGW4bk0xiQs70/mqW7VOgwjnilQCePsl8
NqMDDDaiOw9Nhx8mpvGBRyY=
=Y26w
-----END PGP SIGNATURE-----