[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: OO call vs normal call
- From: David Given <dg@...>
- Date: Mon, 07 May 2007 14:02:21 +0100
-----BEGIN PGP SIGNED MESSAGE-----
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).
┌── ｄｇ＠ｃｏｗｌａｒｋ．ｃｏｍ ─── 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
-----END PGP SIGNATURE-----