changed WeakArray to set emptied slots to zero
authorClaus Gittinger <cg@exept.de>
Fri, 18 Oct 1996 14:36:43 +0200
changeset 1078 f7b6f15899ab
parent 1077 f06cffd904c1
child 1079 7d01a4641ef0
changed WeakArray to set emptied slots to zero instead of nil. This allows easier finding of reclaimed slots (and is also ST-80 compatible). Change needs in-depth testing ...
DevWorkst.st
DeviceWorkstation.st
ResourcePack.st
RsrcPack.st
--- a/DevWorkst.st	Wed Oct 16 10:58:47 1996 +0200
+++ b/DevWorkst.st	Fri Oct 18 14:36:43 1996 +0200
@@ -84,7 +84,7 @@
       resolutionVer   <Number>          pixels per vertical millimeter
 
       idToViewMapping <Dictionary>      maps view-ids to views
-      knownViews      <Collection>      all views known
+      knownViews      <WeakArray>       all of my known views
       knownIds        <Collection>      corresponding device-view ids
       knownBitmaps    <Collection>      all known device bitmaps
       knownBitmapIds  <Collection>      corresponding device-bitmap ids
@@ -568,12 +568,14 @@
 !
 
 knownViews
-    "return a collection of all known views"
+    "return a (non-weak) collection of all known views"
 
     |views|
 
     views := IdentitySet new.
-    knownViews do:[:v | v notNil ifTrue:[views add:v]].
+    knownViews do:[:v | 
+		        (v notNil and:[v ~~ 0]) ifTrue:[views add:v]
+		  ].
     ^ views
 
     "Modified: 15.10.1996 / 12:47:35 / cg"
@@ -2254,9 +2256,16 @@
         
                 
     knownViews notNil ifTrue:[
-      knownViews do:[:aView |
+      1 to:knownViews size do:[:index |
+	  |aView|
+
+	  aView := knownViews at:index.
 	  aView notNil ifTrue:[
-	      aBlock value:aView
+	      aView == 0 ifTrue:[
+	          knownViews at:index put:nil
+	      ] ifFalse:[
+	          aBlock value:aView
+	      ]
 	  ]
       ]
     ]
@@ -2654,9 +2663,10 @@
     knownViews notNil ifTrue:[
 	(knownViews findFirst:[:slot | 
 		slot notNil 
+		and:[slot ~~ 0
 		and:[slot isRootView not 
 		and:[slot superView isNil
-		and:[slot shown]]]]) == 0 ifTrue:[
+		and:[slot shown]]]]]) == 0 ifTrue:[
 	    "/ my last view was closed
 	    dispatching := false.
 	    'DEVWORKST: finished dispatch (last view closed)' infoPrintCR.
@@ -4333,6 +4343,9 @@
 	freeIdx := 1.
     ] ifFalse:[
 	freeIdx := knownViews identityIndexOf:nil.
+	freeIdx == 0 ifTrue:[
+	    freeIdx := knownViews identityIndexOf:0
+	].
 
 "/        1 to:knownViews size do:[:idx |
 "/            |id|
@@ -4408,7 +4421,10 @@
 	 destroy it ...
 	"
 	1 to:knownViews size do:[:idx |
-	    (knownViews at:idx) isNil ifTrue:[
+	    |v|
+
+	    ((v := knownViews at:idx) isNil 
+	    or:[v == 0]) ifTrue:[
 		id := knownIds at:idx.
 		id notNil ifTrue:[
 		    knownIds at:idx put:nil.
@@ -4425,13 +4441,19 @@
 viewFromId:aWindowID
     "given an Id, return the corresponding view."
 
-    |index|
+    |index v|
 
 "/    ^ idToViewMapping at:aNumber ifAbsent:[nil].
 
     index := knownIds indexOf:aWindowID.
     index == 0 ifTrue:[^ nil].
-    ^ knownViews at:index.
+    v := knownViews at:index.
+    v == 0 ifTrue:[
+	knownViews at:index put:nil.
+	knownIds at:index put:nil.
+	^ nil
+    ].
+    ^ v
 ! !
 
 !DeviceWorkstation methodsFor:'window stuff'!
@@ -4526,7 +4548,9 @@
 	knownViews do:[:aView |
 	    |c vid cid|
 
-	    (aView notNil and:[(vid := aView id) notNil]) ifTrue:[
+	    (aView notNil 
+	    and:[aView ~~ 0
+	    and:[(vid := aView id) notNil]]) ifTrue:[
 		c := aView cursor.
 		(c notNil and:[(cid := c id) notNil]) ifTrue:[
 		    self setCursor:cid in:vid
@@ -4576,7 +4600,9 @@
 	    knownViews do:[:aView |
 		|vid|
 
-		(aView notNil and:[(vid := aView id) notNil]) ifTrue:[
+		(aView notNil 
+		and:[aView ~~ 0
+		and:[(vid := aView id) notNil]]) ifTrue:[
 		    self setCursor:id in:vid
 		]
 	    ].
@@ -4699,6 +4725,6 @@
 !DeviceWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Attic/DevWorkst.st,v 1.138 1996-10-15 11:53:13 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Attic/DevWorkst.st,v 1.139 1996-10-18 12:36:24 cg Exp $'
 ! !
 DeviceWorkstation initialize!
--- a/DeviceWorkstation.st	Wed Oct 16 10:58:47 1996 +0200
+++ b/DeviceWorkstation.st	Fri Oct 18 14:36:43 1996 +0200
@@ -84,7 +84,7 @@
       resolutionVer   <Number>          pixels per vertical millimeter
 
       idToViewMapping <Dictionary>      maps view-ids to views
-      knownViews      <Collection>      all views known
+      knownViews      <WeakArray>       all of my known views
       knownIds        <Collection>      corresponding device-view ids
       knownBitmaps    <Collection>      all known device bitmaps
       knownBitmapIds  <Collection>      corresponding device-bitmap ids
@@ -568,12 +568,14 @@
 !
 
 knownViews
-    "return a collection of all known views"
+    "return a (non-weak) collection of all known views"
 
     |views|
 
     views := IdentitySet new.
-    knownViews do:[:v | v notNil ifTrue:[views add:v]].
+    knownViews do:[:v | 
+		        (v notNil and:[v ~~ 0]) ifTrue:[views add:v]
+		  ].
     ^ views
 
     "Modified: 15.10.1996 / 12:47:35 / cg"
@@ -2254,9 +2256,16 @@
         
                 
     knownViews notNil ifTrue:[
-      knownViews do:[:aView |
+      1 to:knownViews size do:[:index |
+	  |aView|
+
+	  aView := knownViews at:index.
 	  aView notNil ifTrue:[
-	      aBlock value:aView
+	      aView == 0 ifTrue:[
+	          knownViews at:index put:nil
+	      ] ifFalse:[
+	          aBlock value:aView
+	      ]
 	  ]
       ]
     ]
@@ -2654,9 +2663,10 @@
     knownViews notNil ifTrue:[
 	(knownViews findFirst:[:slot | 
 		slot notNil 
+		and:[slot ~~ 0
 		and:[slot isRootView not 
 		and:[slot superView isNil
-		and:[slot shown]]]]) == 0 ifTrue:[
+		and:[slot shown]]]]]) == 0 ifTrue:[
 	    "/ my last view was closed
 	    dispatching := false.
 	    'DEVWORKST: finished dispatch (last view closed)' infoPrintCR.
@@ -4333,6 +4343,9 @@
 	freeIdx := 1.
     ] ifFalse:[
 	freeIdx := knownViews identityIndexOf:nil.
+	freeIdx == 0 ifTrue:[
+	    freeIdx := knownViews identityIndexOf:0
+	].
 
 "/        1 to:knownViews size do:[:idx |
 "/            |id|
@@ -4408,7 +4421,10 @@
 	 destroy it ...
 	"
 	1 to:knownViews size do:[:idx |
-	    (knownViews at:idx) isNil ifTrue:[
+	    |v|
+
+	    ((v := knownViews at:idx) isNil 
+	    or:[v == 0]) ifTrue:[
 		id := knownIds at:idx.
 		id notNil ifTrue:[
 		    knownIds at:idx put:nil.
@@ -4425,13 +4441,19 @@
 viewFromId:aWindowID
     "given an Id, return the corresponding view."
 
-    |index|
+    |index v|
 
 "/    ^ idToViewMapping at:aNumber ifAbsent:[nil].
 
     index := knownIds indexOf:aWindowID.
     index == 0 ifTrue:[^ nil].
-    ^ knownViews at:index.
+    v := knownViews at:index.
+    v == 0 ifTrue:[
+	knownViews at:index put:nil.
+	knownIds at:index put:nil.
+	^ nil
+    ].
+    ^ v
 ! !
 
 !DeviceWorkstation methodsFor:'window stuff'!
@@ -4526,7 +4548,9 @@
 	knownViews do:[:aView |
 	    |c vid cid|
 
-	    (aView notNil and:[(vid := aView id) notNil]) ifTrue:[
+	    (aView notNil 
+	    and:[aView ~~ 0
+	    and:[(vid := aView id) notNil]]) ifTrue:[
 		c := aView cursor.
 		(c notNil and:[(cid := c id) notNil]) ifTrue:[
 		    self setCursor:cid in:vid
@@ -4576,7 +4600,9 @@
 	    knownViews do:[:aView |
 		|vid|
 
-		(aView notNil and:[(vid := aView id) notNil]) ifTrue:[
+		(aView notNil 
+		and:[aView ~~ 0
+		and:[(vid := aView id) notNil]]) ifTrue:[
 		    self setCursor:id in:vid
 		]
 	    ].
@@ -4699,6 +4725,6 @@
 !DeviceWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/DeviceWorkstation.st,v 1.138 1996-10-15 11:53:13 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/DeviceWorkstation.st,v 1.139 1996-10-18 12:36:24 cg Exp $'
 ! !
 DeviceWorkstation initialize!
--- a/ResourcePack.st	Wed Oct 16 10:58:47 1996 +0200
+++ b/ResourcePack.st	Fri Oct 18 14:36:43 1996 +0200
@@ -240,6 +240,9 @@
 
     idx := Packs identityIndexOf:nil.
     idx == 0 ifTrue:[
+	idx := Packs identityIndexOf:0
+    ].
+    idx == 0 ifTrue:[
 	"
 	 throw away oldest
 	"
@@ -262,7 +265,8 @@
 	|aPack|
 
 	aPack := Packs at:idx.
-	aPack notNil ifTrue:[
+	(aPack notNil 
+	and:[aPack ~~ 0]) ifTrue:[
 	    aClassname = aPack packsClassName ifTrue:[
 		"
 		 bring to end for LRU
@@ -575,6 +579,6 @@
 !ResourcePack  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.36 1996-09-09 16:58:15 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.37 1996-10-18 12:36:43 cg Exp $'
 ! !
 ResourcePack initialize!
--- a/RsrcPack.st	Wed Oct 16 10:58:47 1996 +0200
+++ b/RsrcPack.st	Fri Oct 18 14:36:43 1996 +0200
@@ -240,6 +240,9 @@
 
     idx := Packs identityIndexOf:nil.
     idx == 0 ifTrue:[
+	idx := Packs identityIndexOf:0
+    ].
+    idx == 0 ifTrue:[
 	"
 	 throw away oldest
 	"
@@ -262,7 +265,8 @@
 	|aPack|
 
 	aPack := Packs at:idx.
-	aPack notNil ifTrue:[
+	(aPack notNil 
+	and:[aPack ~~ 0]) ifTrue:[
 	    aClassname = aPack packsClassName ifTrue:[
 		"
 		 bring to end for LRU
@@ -575,6 +579,6 @@
 !ResourcePack  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Attic/RsrcPack.st,v 1.36 1996-09-09 16:58:15 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Attic/RsrcPack.st,v 1.37 1996-10-18 12:36:43 cg Exp $'
 ! !
 ResourcePack initialize!