ClosestStorm / v8cgi

Automatically exported from code.google.com/p/v8cgi
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

JavaScript code and performance improvements #95

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1.Where it was safe == operators have been replaced with === to avoid 
unnecessary type casting.
2.length attribute of arrays assign to variable to speed up the for-loop 
execution
3. hasOwnProperty verification for all for-in loops added - to avoid 
unnecessary walk-through prototype elements
4. missing semicolons added
5. double variable declarations removed from some functions  

Original issue reported on code.google.com by ddrcode on 16 Jun 2011 at 10:08

Attachments:

GoogleCodeExporter commented 9 years ago
Those hasOwnProperty checks seem to be unnecessary: all those objects are 
simple JS data structures with __proto__ === Object.prototype, e.g. no non-own 
properties are being enumerated... ?

Original comment by ondrej.zara on 17 Jun 2011 at 10:08

GoogleCodeExporter commented 9 years ago
Some of JS developers would say that hasOwnProperty check should be an integral 
part of for..in loop. Even if there is nothing added to object's prototype. 
However it is just theoretical discussion. In practice - I never had a need to 
navigate through prototype properties of an object, this is why I always add 
the check. In such case I never have to bother when I add something enumerable 
to the prototype...

Original comment by ddrcode on 20 Jun 2011 at 9:10

GoogleCodeExporter commented 9 years ago
I can guarantee that I *never* modify Object.prototype, which is why adding 
hasOwnProperty check to "for (var p in {})" is redundant...

Also, consistently, I never enumerate non-Objects with "for (var p in what)" - 
which is why I can freely extend their prototypes :)

Original comment by ondrej.zara on 22 Jun 2011 at 8:07

GoogleCodeExporter commented 9 years ago
Revision 918 applies those parts of this patch which optimize array length 
getters in loops.

Original comment by ondrej.zara on 27 Jul 2011 at 11:26

GoogleCodeExporter commented 9 years ago
Thanks, the array lengths were the most important. 

Original comment by ddrcode on 3 Sep 2011 at 11:39