--- a/Rectangle.st Fri Feb 25 14:02:06 1994 +0100
+++ b/Rectangle.st Fri Feb 25 14:03:34 1994 +0100
@@ -38,7 +38,7 @@
width <Number> the width of the rectangle
height <Number> the height of the rectangle
-$Header: /cvs/stx/stx/libbasic/Rectangle.st,v 1.6 1994-01-08 16:22:49 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Rectangle.st,v 1.7 1994-02-25 13:03:34 claus Exp $
written 89 by claus
'!
@@ -55,26 +55,30 @@
"create and return a new Rectangle giving top-left point and extent point"
%{ /* NOCONTEXT */
- OBJ newRect;
- extern char *newNextPtr, *newEndPtr;
+ REGISTER OBJ newRect;
+ REGISTER struct point *p;
extern OBJ Point;
/* short cut - rectangles are created so often ... */
if (_CanDoQuickNew(OHDR_SIZE + 4*sizeof(OBJ))) {
- if ((self == Rectangle)
- && _isPoint(origin)
- && _isPoint(extent)) {
- _qCheckedAlignedNew(newRect, OHDR_SIZE + 4*sizeof(OBJ));
- _InstPtr(newRect)->o_class = Rectangle;
- _InstPtr(newRect)->i_instvars[0] = _PointInstPtr(origin)->p_x;
- _InstPtr(newRect)->i_instvars[1] = _PointInstPtr(origin)->p_y;
- _InstPtr(newRect)->i_instvars[2] = _PointInstPtr(extent)->p_x;
- _InstPtr(newRect)->i_instvars[3] = _PointInstPtr(extent)->p_y;
- __STORE(newRect, _PointInstPtr(origin)->p_x);
- __STORE(newRect, _PointInstPtr(origin)->p_y);
- __STORE(newRect, _PointInstPtr(extent)->p_x);
- __STORE(newRect, _PointInstPtr(extent)->p_y);
- RETURN ( newRect );
+ if (self == Rectangle) {
+ if (__isPoint(origin) && __isPoint(extent)) {
+ _qCheckedAlignedNew(newRect, OHDR_SIZE + 4*sizeof(OBJ));
+ _InstPtr(newRect)->o_class = Rectangle;
+
+ p = _PointInstPtr(origin);
+ _InstPtr(newRect)->i_instvars[0] = p->p_x;
+ _InstPtr(newRect)->i_instvars[1] = p->p_y;
+ __STORE(newRect, p->p_x);
+ __STORE(newRect, p->p_y);
+
+ p = _PointInstPtr(extent);
+ _InstPtr(newRect)->i_instvars[2] = p->p_x;
+ _InstPtr(newRect)->i_instvars[3] = p->p_y;
+ __STORE(newRect, p->p_x);
+ __STORE(newRect, p->p_y);
+ RETURN ( newRect );
+ }
}
}
%}
@@ -87,8 +91,7 @@
and width, height"
%{ /* NOCONTEXT */
- OBJ newRect;
- extern char *newNextPtr, *newEndPtr;
+ REGISTER OBJ newRect;
if (_CanDoQuickNew(OHDR_SIZE + 4*sizeof(OBJ))) {
/* short cut - rectangles are created so often ... */
@@ -99,10 +102,11 @@
_InstPtr(newRect)->i_instvars[1] = top;
_InstPtr(newRect)->i_instvars[2] = w;
_InstPtr(newRect)->i_instvars[3] = h;
- __STORE(newRect, left);
- __STORE(newRect, top);
- __STORE(newRect, w);
- __STORE(newRect, h);
+
+ __STORE(newRect, _InstPtr(newRect)->i_instvars[0]);
+ __STORE(newRect, _InstPtr(newRect)->i_instvars[1]);
+ __STORE(newRect, _InstPtr(newRect)->i_instvars[2]);
+ __STORE(newRect, _InstPtr(newRect)->i_instvars[3]);
RETURN ( newRect );
}
}
@@ -336,18 +340,25 @@
rectangle as the receiver"
%{ /* NOCONTEXT */
- static struct inlineCache eq = _ILC1;
+ REGISTER struct instance *mySelf, *other;
- if (_isNonNilObject(aRectangle) && _qClass(aRectangle) == Rectangle) {
- if (( _InstPtr(self)->i_instvars[0] == _InstPtr(aRectangle)->i_instvars[0] )
- && ( _InstPtr(self)->i_instvars[1] == _InstPtr(aRectangle)->i_instvars[1] )
- && ( _InstPtr(self)->i_instvars[2] == _InstPtr(aRectangle)->i_instvars[2] )
- && ( _InstPtr(self)->i_instvars[3] == _InstPtr(aRectangle)->i_instvars[3] )) {
+ /*
+ * handle the common case quickly
+ */
+ if (_isNonNilObject(aRectangle)
+ && _qClass(aRectangle) == Rectangle) {
+ mySelf = _InstPtr(self);
+ other = _InstPtr(aRectangle);
+ if ((mySelf->i_instvars[0] == other->i_instvars[0])
+ && (mySelf->i_instvars[1] == other->i_instvars[1])
+ && (mySelf->i_instvars[2] == other->i_instvars[2])
+ && (mySelf->i_instvars[3] == other->i_instvars[3])) {
RETURN ( true );
}
}
%}
.
+
(aRectangle isKindOf:Rectangle) ifFalse:[^ false].
left = aRectangle left ifFalse:[^ false].
@@ -355,6 +366,14 @@
width = aRectangle width ifFalse:[^ false].
height = aRectangle height ifFalse:[^ false].
^ true
+!
+
+hash
+ "return an integer useful for hashing -
+ redefined since = is redefined here"
+
+ ^ ((left hash bitShift:16) bitXor:(top hash bitShift:16))
+ + ((width hash) bitXor:(height hash))
! !
!Rectangle methodsFor:'testing'!
@@ -496,9 +515,10 @@
|amountPoint|
amountPoint := amount asPoint.
- ^ Rectangle left:(left + amountPoint x) top:(top + amountPoint y)
- width:(width)
- height:(height)
+ ^ Rectangle left:(left + amountPoint x)
+ top:(top + amountPoint y)
+ width:width
+ height:height
!
moveTo: aPoint
@@ -609,19 +629,11 @@
!Rectangle methodsFor:'printing'!
-printString
- "return a string for printing"
-
- ^ 'Rectangle origin:'
- , self origin printString
- , ' corner:'
- , self corner printString
-!
-
printOn:aStream
"print the receiver on aStream"
- aStream nextPutAll:'Rectangle origin:'.
+ aStream nextPutAll:(self class name).
+ aStream nextPutAll:' origin:'.
(self origin) printOn:aStream.
aStream nextPutAll:' corner:'.
(self corner) printOn:aStream
@@ -631,11 +643,11 @@
"store the receiver on aStream; i.e. print an expression which will
reconstruct the receiver"
- aStream nextPutAll:'('.
+ aStream nextPut:$(.
aStream nextPutAll:(self class name).
- aStream nextPutAll:' new origin:'.
- aStream nextPutAll:(self origin printString).
+ aStream nextPutAll:' origin:'.
+ (self origin) storeOn:aStream.
aStream nextPutAll:' corner:'.
- aStream nextPutAll:(self corner printString).
- aStream nextPutAll:'('
+ (self corner) storeOn:aStream.
+ aStream nextPut:$)
! !