Some more optimizations for JS minifier and V8.

This commit is contained in:
Jürg Lehni 2014-01-05 21:07:11 +01:00
parent 1bf7107918
commit 4a95f6e4a6
3 changed files with 14 additions and 9 deletions

View file

@ -449,14 +449,17 @@ var Point = Base.extend(/** @lends Point# */{
* remain squared, or its square root should be calculated.
* @return {Number}
*/
getDistance: function(point, squared) {
getDistance: function(_point, squared) {
// NOTE: Although we're reading from the argument list, we need the
// above arguments to prevent a bean from being created.
point = Point.read(arguments);
squared = Base.read(arguments);
var x = point.x - this.x,
// above arguments to prevent beans from being created (Strap.js issue).
// And for browser optimization we shouldn't re-asign an object to it,
// but we need to prevent the minifier from removing it again, so:
var point = Point.read(arguments),
x = point.x - this.x,
y = point.y - this.y,
d = x * x + y * y;
// Reassigning boolean values to arguments is apparently OK.
squared = Base.read(arguments);
return squared ? d : Math.sqrt(d);
},
@ -638,9 +641,12 @@ var Point = Base.extend(/** @lends Point# */{
* @param {Point} point
* @return {Number} the angle between the two vectors
*/
getDirectedAngle: function(point) {
getDirectedAngle: function(_point) {
// NOTE: Although we're reading from the argument list, we need the
// above argument to prevent a bean from being created.
// above arguments to prevent beans from being created (Strap.js issue).
// And for browser optimization we shouldn't re-asign an object to it,
// but we need to prevent the minifier from removing it again, so:
var point = _point;
point = Point.read(arguments);
return Math.atan2(this.cross(point), this.dot(point)) * 180 / Math.PI;
},

View file

@ -14,7 +14,7 @@
* @name PaperScript
* @namespace
*/
var PaperScript = Base.exports.PaperScript = (function() {
Base.exports.PaperScript = (function() {
// Locally turn of exports and define for inlined acorn / esprima.
// Just declaring the local vars is enough, as they will be undefined.
var exports, define,

View file

@ -1137,7 +1137,6 @@ var Color = Base.extend(new function() {
this[name] = function(color) {
color = Color.read(arguments);
var type = this._type,
properties = this._properties,
components1 = this._components,
components2 = color._convert(type);
for (var i = 0, l = components1.length; i < l; i++)