[wp-hackers] Micro optimization - is_a() vs instanceof

Justas Butkus jbutkus at time.ly
Fri Jan 4 18:39:41 UTC 2013


$ spatch -e 's/is_a( X, Y )/ ( X instanceof Y ) /' /path/to/wordpress/core

That is bullet-proof 1 minute replacement, given that Facebook Pfff 
(https://github.com/facebook/pfff/wiki/Spatch) is installed.

Bullet-proof, because spatch operates on a abstract syntax tree level, 
so no quote will be missed, etc., etc.

Just a hint, how this may be achieved quickly, in error-prone way.


-- 
Regards,
Justas B.

On 2013.01.04 20:33, Jeff Morris wrote:
> On 04/01/2013 17:32, Otto wrote:
>> The difference is probably negliable, but it adds up over time. It
>> would make sense to switch to instanceof anywhere that it is possible
>> to do so, however I don't think it is a pressing concern. One of those
>> fix-it-if-you-spot-it things.
>
> IDE search on WP 3.5, "is_a(":
>
> /wp-includes/ : 53 matches
> /wp-admin/includes/ : 4 matches
>
> About an hour's work to refactor, and that's being meticulous.
>
>
> For bbpress 2.2.3 I also got:
> /wp-content/plugins/bbpress/includes/ : 7 matches
>
> A dime to a dollar says they'll fix it before WP core does.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list