Hi Paolo,

here is the patch for beConsistent refactoring

Gwen
>From 0a03265376b7ded2e1c47cb43ad7f44a2c6f9987 Mon Sep 17 00:00:00 2001
From: Gwenael Casaccio <[email protected]>
Date: Mon, 27 Jun 2011 16:32:56 +0200
Subject: [PATCH 2/3] move beConsistent

---
 kernel/OrderColl.st   |   10 ---------
 kernel/SortCollect.st |   51 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 10 deletions(-)

diff --git a/kernel/OrderColl.st b/kernel/OrderColl.st
index 0adfddc..63154dc 100644
--- a/kernel/OrderColl.st
+++ b/kernel/OrderColl.st
@@ -61,7 +61,6 @@ on content (such as add:after:)'>
 
         <category: 'enumerating'>
         | index |
-        self beConsistent.
         index := firstIndex.
         [ index <= lastIndex ] whileTrue: [
             aBlock value: (self basicAt: index).
@@ -72,7 +71,6 @@ on content (such as add:after:)'>
 	"Answer the first item of the receiver"
 
 	<category: 'accessing'>
-	self beConsistent.
 	^lastIndex >= firstIndex
 	    ifTrue: [self basicAt: firstIndex]
 	    ifFalse: [SystemExceptions.IndexOutOfRange signalOn: self withIndex: 1]
@@ -82,7 +80,6 @@ on content (such as add:after:)'>
 	"Answer the last item of the receiver"
 
 	<category: 'accessing'>
-	self beConsistent.
 	^lastIndex >= firstIndex
 	    ifTrue: [self basicAt: lastIndex]
 	    ifFalse: [SystemExceptions.IndexOutOfRange signalOn: self withIndex: 0]
@@ -93,7 +90,6 @@ on content (such as add:after:)'>
 
 	<category: 'accessing'>
 	| index |
-	self beConsistent.
 	index := anIndex + firstIndex - 1.
 	^(index >= firstIndex and: [index <= lastIndex]) 
 	    ifTrue: [self basicAt: index]
@@ -105,7 +101,6 @@ on content (such as add:after:)'>
 
 	<category: 'accessing'>
 	| index |
-	self beConsistent.
 	index := anIndex + firstIndex - 1.
 	(index >= firstIndex and: [index <= lastIndex]) 
 	    ifTrue: [^self basicAt: index put: anObject]
@@ -292,7 +287,6 @@ on content (such as add:after:)'>
 
 	<category: 'removing'>
 	| answer |
-	self beConsistent.
 	lastIndex < firstIndex 
 	    ifTrue: [^SystemExceptions.EmptyCollection signalOn: self].
 	answer := self basicAt: firstIndex.	"Get the element"
@@ -300,7 +294,6 @@ on content (such as add:after:)'>
 	lastIndex = firstIndex 
 	    ifTrue: [self initIndices]
 	    ifFalse: [firstIndex := firstIndex + 1].
-	self size < self shrinkSize ifTrue: [self shrink].
 	^answer
     ]
 
@@ -310,7 +303,6 @@ on content (such as add:after:)'>
 
 	<category: 'removing'>
 	| answer |
-	self beConsistent.
 	lastIndex < firstIndex 
 	    ifTrue: [^SystemExceptions.EmptyCollection signalOn: self].
 	answer := self basicAt: lastIndex.	"Get the element"
@@ -318,7 +310,6 @@ on content (such as add:after:)'>
 	lastIndex = firstIndex 
 	    ifTrue: [self initIndices]
 	    ifFalse: [lastIndex := lastIndex - 1].
-	self size < self shrinkSize ifTrue: [self shrink].
 	^answer
     ]
 
@@ -370,7 +361,6 @@ on content (such as add:after:)'>
 
 	<category: 'private methods'>
 	| answer |
-	self beConsistent.
 	lastIndex < firstIndex 
 	    ifTrue: [^SystemExceptions.EmptyCollection signalOn: self].
 	(anIndex < 1 or: [anIndex > self size]) 
diff --git a/kernel/SortCollect.st b/kernel/SortCollect.st
index fb5c13e..5e33599 100644
--- a/kernel/SortCollect.st
+++ b/kernel/SortCollect.st
@@ -113,6 +113,56 @@ above criteria -- actually any object which responds to #value:value:.'>
 	self shouldNotImplement
     ]
 
+    first [
+        "Answer the first item of the receiver"
+
+        <category: 'accessing'>
+        self beConsistent.
+        ^ super first
+    ]
+
+    last [
+        "Answer the last item of the receiver"
+
+        <category: 'accessing'>
+        self beConsistent.
+        ^ super last
+    ]
+
+    at: anIndex [
+        "Answer the anIndex-th item of the receiver"
+
+        <category: 'accessing'>
+        self beConsistent.
+	^ super at: anIndex
+    ]
+
+    do: aBlock [
+        "Evaluate aBlock for all the elements in the collection"
+
+        <category: 'enumerating'>
+        self beConsistent.
+	super do: aBlock
+    ]
+
+    removeFirst [
+        "Remove an object from the start of the receiver. Fail if the receiver
+         is empty"
+
+        <category: 'removing'>
+        self beConsistent.
+        ^ super removeFirst
+    ]
+
+    removeLast [
+        "Remove an object from the end of the receiver. Fail if the receiver
+         is empty"
+
+        <category: 'removing'>
+        self beConsistent.
+        ^ super removeLast
+    ]
+
     last [
 	"Answer the last item of the receiver"
 
@@ -282,6 +332,7 @@ above criteria -- actually any object which responds to #value:value:.'>
 
 	<category: 'private methods'>
 	| answer |
+	self beConsistent.
 	answer := super basicRemoveAtIndex: anIndex.
 
 	"Ensure the invariant that lastOrdered <= lastIndex, otherwise
-- 
1.7.4.1

>From 85ca6795a63ba4406a0da9e4537d52b1a524daf9 Mon Sep 17 00:00:00 2001
From: Gwenael Casaccio <[email protected]>
Date: Mon, 27 Jun 2011 17:13:53 +0200
Subject: [PATCH 3/3] beConsistent refactoring

---
 kernel/Dictionary.st  |    4 ----
 kernel/HashedColl.st  |    3 ---
 kernel/IdentDict.st   |    4 ----
 kernel/IdentitySet.st |    2 --
 kernel/Set.st         |    2 --
 kernel/WeakObjects.st |   27 +++++++++++++++++++++++++++
 6 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/kernel/Dictionary.st b/kernel/Dictionary.st
index 9f2f10e..e5d7914 100644
--- a/kernel/Dictionary.st
+++ b/kernel/Dictionary.st
@@ -568,8 +568,6 @@ certain special cases.'>
 
         <category: 'private methods'>
         | index size element |
-        self beConsistent.
-
         "Sorry for the lack of readability, but I want speed... :-)"
         index := (anObject key hash scramble bitAnd: (size := self primSize) - 1) + 1.
    
@@ -585,8 +583,6 @@ certain special cases.'>
 
 	<category: 'private methods'>
 	| index size element |
-	self beConsistent.
-
 	"Sorry for the lack of readability, but I want speed... :-)"
 	index := (anObject hash scramble bitAnd: (size := self primSize) - 1) + 1.
 	
diff --git a/kernel/HashedColl.st b/kernel/HashedColl.st
index 1af0fc0..345e1ec 100644
--- a/kernel/HashedColl.st
+++ b/kernel/HashedColl.st
@@ -196,7 +196,6 @@ give fast responses on their presence in the collection.'>
 	"Enumerate all the non-nil members of the set"
 
 	<category: 'enumerating the elements of a collection'>
-	self beConsistent.
 	1 to: self primSize
 	    do: [:i | (self primAt: i) notNil ifTrue: [aBlock value: (self primAt: i)]]
     ]
@@ -334,8 +333,6 @@ give fast responses on their presence in the collection.'>
 
         <category: 'private methods'>
         | index size element |
-        self beConsistent.
-
         "Sorry for the lack of readability, but I want speed... :-)"
         index := (anObject hash scramble bitAnd: (size := self primSize) - 1) + 1.
    
diff --git a/kernel/IdentDict.st b/kernel/IdentDict.st
index 3e7130d..0db6414 100644
--- a/kernel/IdentDict.st
+++ b/kernel/IdentDict.st
@@ -60,8 +60,6 @@ comparision message == to determine equivalence of indices.'>
 
         <category: 'private methods'>
         | index size element |
-        self beConsistent.
-
         "Sorry for the lack of readability, but I want speed... :-)"
         index := (anObject identityHash scramble bitAnd: (size := self primSize) - 1) + 1.
    
@@ -77,8 +75,6 @@ comparision message == to determine equivalence of indices.'>
 
 	<category: 'private methods'>
 	| index size element |
-	self beConsistent.
-
 	"Sorry for the lack of readability, but I want speed... :-)"
 	index := (anObject identityHash scramble 
 		    bitAnd: (size := self primSize) - 1) + 1.
diff --git a/kernel/IdentitySet.st b/kernel/IdentitySet.st
index ebe73f5..637e0ea 100644
--- a/kernel/IdentitySet.st
+++ b/kernel/IdentitySet.st
@@ -59,8 +59,6 @@ use the == operator to determine duplication of objects.'>
 
 	<category: 'private methods'>
 	| index size element |
-	self beConsistent.
-
 	"Sorry for the lack of readability, but I want speed... :-)"
 	index := (anObject identityHash scramble 
 		    bitAnd: (size := self primSize) - 1) + 1.
diff --git a/kernel/Set.st b/kernel/Set.st
index 56fbddf..6ed2d9d 100644
--- a/kernel/Set.st
+++ b/kernel/Set.st
@@ -123,8 +123,6 @@ on my instances.'>
 
 	<category: 'private methods'>
 	| index size element |
-	self beConsistent.
-
 	"Sorry for the lack of readability, but I want speed... :-)"
 	index := (anObject hash scramble bitAnd: (size := self primSize) - 1) + 1.
 	
diff --git a/kernel/WeakObjects.st b/kernel/WeakObjects.st
index 25cf7f9..52eb297 100644
--- a/kernel/WeakObjects.st
+++ b/kernel/WeakObjects.st
@@ -506,6 +506,33 @@ for the garbage collected values'>
 		(key at: i) isNil 
 		    ifFalse: [self whileGrowingAt: (key at: i) put: (val at: i)]]
     ]
+
+    findElementIndex: anObject [
+        "Tries to see where anObject can be placed as an indexed variable.
+         As soon as nil is found, the index of that slot is answered.
+         anObject also comes from an indexed variable."
+
+        <category: 'private methods'>
+        self beConsistent.
+	^ super findElementIndex: anObject
+    ]
+
+    findIndex: anObject [
+        "Tries to see if anObject exists as an indexed variable. As soon as nil
+         or anObject is found, the index of that slot is answered"
+
+        <category: 'private methods'>
+        self beConsistent.
+	^ super findIndex: anObject
+    ]
+
+    do: aBlock [
+        "Enumerate all the non-nil members of the set"
+
+        <category: 'enumerating the elements of a collection'>
+        self beConsistent.
+	super do: aBlock
+    ]
 ]
 
 
-- 
1.7.4.1

_______________________________________________
help-smalltalk mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to