--- a/Object.st Fri May 16 17:04:58 1997 +0200
+++ b/Object.st Tue May 20 15:54:52 1997 +0200
@@ -1759,90 +1759,65 @@
int flags;
sz = __qSize(self);
-
- __PROTECT__(self);
- __qNew(theCopy, sz);
- __UNPROTECT__(slf);
- if (theCopy) {
- spc = __qSpace(theCopy);
-
- theCopy->o_class = cls = __qClass(slf); __STORE_SPC(theCopy, cls, spc);
-
- sz = sz - OHDR_SIZE;
- if (sz) {
- char *src, *dst;
-
- src = (char *)(__InstPtr(slf)->i_instvars);
- dst = (char *)(__InstPtr(theCopy)->i_instvars);
+ cls = __qClass(self);
+ flags = __intVal(__ClassInstPtr(cls)->c_flags);
+
+ /*
+ * bail out for special objects ..
+ */
+ if (((flags & ~ARRAYMASK) == 0)
+ && ((flags & ARRAYMASK) != WKPOINTERARRAY)) {
+ __PROTECT2__(self, cls);
+ __qNew(theCopy, sz);
+ __UNPROTECT2__(cls, slf);
+ if (theCopy) {
+ spc = __qSpace(theCopy);
+
+ theCopy->o_class = cls; __STORE_SPC(theCopy, cls, spc);
+
+ sz = sz - OHDR_SIZE;
+ if (sz) {
+ char *src, *dst;
+
+ src = (char *)(__InstPtr(slf)->i_instvars);
+ dst = (char *)(__InstPtr(theCopy)->i_instvars);
#ifdef bcopy4
- {
- /* care for odd-number of longs */
- int nW = sz >> 2;
-
- if (sz & 3) {
- nW++;
+ {
+ /* care for odd-number of longs */
+ int nW = sz >> 2;
+
+ if (sz & 3) {
+ nW++;
+ }
+
+ bcopy4(src, dst, nW);
}
-
- bcopy4(src, dst, nW);
- }
#else
- bcopy(src, dst, sz);
+ bcopy(src, dst, sz);
#endif
- flags = __intVal(__ClassInstPtr(cls)->c_flags) & ARRAYMASK;
- if ((flags == POINTERARRAY) || (flags == WKPOINTERARRAY)) {
- ninsts = __BYTES2OBJS__(sz);
- } else {
- ninsts = __intVal(__ClassInstPtr(cls)->c_ninstvars);
+ flags &= ARRAYMASK;
+ if ((flags == POINTERARRAY) || (flags == WKPOINTERARRAY)) {
+ ninsts = __BYTES2OBJS__(sz);
+ } else {
+ ninsts = __intVal(__ClassInstPtr(cls)->c_ninstvars);
+ }
+ if (ninsts) {
+ do {
+ OBJ el;
+
+ el = __InstPtr(theCopy)->i_instvars[ninsts-1];
+ __STORE_SPC(theCopy, el, spc);
+ } while (--ninsts);
+ }
}
- if (ninsts) {
- do {
- OBJ el;
-
- el = __InstPtr(theCopy)->i_instvars[ninsts-1];
- __STORE_SPC(theCopy, el, spc);
- } while (--ninsts);
- }
+ RETURN (theCopy);
}
- RETURN (theCopy);
}
%}.
- "
- memory allocation failed.
- When we arrive here, there was no memory, even after
- a garbage collect.
- This means, that the VM wanted to get some more memory from the
- Operatingsystem, which was not kind enough to give it.
- Bad luck - you should increase the swap space on your machine.
- "
- ^ ObjectMemory allocationFailureSignal raise.
-
-"/
-"/ the above is equivalent to the code below (but much faster) ...
-"/
-"/ |myClass aCopy
-"/ sz "{ Class: SmallInteger }" |
-"/
-"/ myClass := self class.
-"/ myClass isVariable ifTrue:[
-"/ sz := self basicSize.
-"/ aCopy := myClass basicNew:sz.
-"/
-"/ "copy the indexed variables"
-"/ 1 to:sz do:[:i |
-"/ aCopy basicAt:i put:(self basicAt:i)
-"/ ]
-"/ ] ifFalse:[
-"/ aCopy := myClass basicNew
-"/ ].
-"/
-"/ "copy the instance variables"
-"/ sz := myClass instSize.
-"/ 1 to:sz do:[:i |
-"/ aCopy instVarAt:i put:(self instVarAt:i)
-"/ ].
-"/
-"/ ^ aCopy
+ "/ fallBack for special objects & memoryAllocation failure case
+
+ ^ self slowShallowCopy
!
@@ -1895,6 +1870,36 @@
a at:3 put:a.
a simpleDeepCopy
"
+!
+
+slowShallowCopy
+ "return a copy of the object with shared subobjects (a shallow copy)
+ i.e. the copy shares referenced instvars with its original.
+ This method is only invoked as a fallback from #shallowCopy."
+
+ |myClass aCopy
+ sz "{ Class: SmallInteger }" |
+
+ myClass := self class.
+ myClass isVariable ifTrue:[
+ sz := self basicSize.
+ aCopy := myClass basicNew:sz.
+
+ "copy the indexed variables"
+ 1 to:sz do:[:i |
+ aCopy basicAt:i put:(self basicAt:i)
+ ]
+ ] ifFalse:[
+ aCopy := myClass basicNew
+ ].
+
+ "copy the instance variables"
+ sz := myClass instSize.
+ 1 to:sz do:[:i |
+ aCopy instVarAt:i put:(self instVarAt:i)
+ ].
+
+ ^ aCopy
! !
!Object methodsFor:'debugging'!
@@ -5979,6 +5984,6 @@
!Object class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.191 1997-05-14 14:44:23 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.192 1997-05-20 13:54:52 cg Exp $'
! !
Object initialize!