Optimise read() functions to only convert if argument is not of desired type already.

This commit is contained in:
Jürg Lehni 2011-02-13 16:05:19 +00:00
parent d67055b09b
commit 0ac19a8e82
4 changed files with 14 additions and 4 deletions

View file

@ -273,12 +273,15 @@ var Point = Base.extend({
statics: { statics: {
read: function(args) { read: function(args) {
if(args.length) { if (args.length == 1 && args[0] instanceof Point) {
return args[0];
} else if (args.length) {
var point = new Point(); var point = new Point();
point.initialize.apply(point, args); point.initialize.apply(point, args);
return point; return point;
} }
}, },
min: function(point1, point2) { min: function(point1, point2) {
return new Point( return new Point(
Math.min(point1.x, point2.x), Math.min(point1.x, point2.x),

View file

@ -278,7 +278,9 @@ Rectangle = Base.extend({
statics: { statics: {
read: function(args) { read: function(args) {
if(args.length) { if (args.length == 1 && args[0] instanceof Rectangle) {
return args[0];
} else if (args.length) {
var rect = new Rectangle(); var rect = new Rectangle();
rect.initialize.apply(rect, args); rect.initialize.apply(rect, args);
return rect; return rect;

View file

@ -88,12 +88,15 @@ var Size = Base.extend({
statics: { statics: {
read: function(args) { read: function(args) {
if(args.length) { if (args.length == 1 && args[0] instanceof Size) {
return args[0];
} else if (args.length) {
var size = new Size(); var size = new Size();
size.initialize.apply(size, args); size.initialize.apply(size, args);
return size; return size;
} }
}, },
min: function(Size1, Size2) { min: function(Size1, Size2) {
return new Size( return new Size(
Math.min(Size1.width, Size2.width), Math.min(Size1.width, Size2.width),

View file

@ -135,7 +135,9 @@ Segment = Base.extend({
statics: { statics: {
read: function(args) { read: function(args) {
if(args.length && args[0] != null) { if (args.length == 1 && args[0] instanceof Segment) {
return args[0];
} else if (args.length && args[0] != null) {
var segment = new Segment(); var segment = new Segment();
segment.initialize.apply(segment, args); segment.initialize.apply(segment, args);
return segment; return segment;