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

View file

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

View file

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