On 06/27/2011 06:52 PM, Paolo Bonzini wrote:
On 06/27/2011 05:26 PM, Gwenael Casaccio wrote:
Hi Paolo,
here is the patch for beConsistent refactoring
Gwen
_______________________________________________
help-smalltalk mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Please do the same for hashedCollection/WeakValueLookupTable, and check
all senders of beConsistent.
Paolo
This patch is better #beConsistent is removed from
Collection and is only in WeakObject.st and SortedOrderedCollection.st
Gwen
diff --git a/kernel/BindingDict.st b/kernel/BindingDict.st
index 66d58f2..bbc2da9 100644
--- a/kernel/BindingDict.st
+++ b/kernel/BindingDict.st
@@ -238,8 +238,6 @@ more speed.'>
<category: 'private'>
| 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/Collection.st b/kernel/Collection.st
index 4aff642..948b62f 100644
--- a/kernel/Collection.st
+++ b/kernel/Collection.st
@@ -320,21 +320,6 @@ of objects.'>
^self isEmpty ifTrue: [#()] ifFalse: [self anyOne species join: self]
]
- beConsistent [
- "This method is private, but it is quite interesting so it is
- documented. It ensures that a collection is in a consistent
- state before attempting to iterate on it; its presence reduces
- the number of overrides needed by collections who try to
- amortize their execution times. The default implementation
- does nothing, so it is optimized out by the virtual machine
- and so it loses very little on the performance side. Note
- that descendants of Collection have to call it explicitly
- since #do: is abstract in Collection."
-
- <category: 'enumeration'>
-
- ]
-
readStream [
"Answer a stream that gives elements of the receiver"
@@ -571,7 +556,6 @@ of objects.'>
<category: 'printing'>
| instVars output object |
- self beConsistent.
aStream
nextPutAll: 'An instance of ';
print: self class;
diff --git a/kernel/Dictionary.st b/kernel/Dictionary.st
index 9f2f10e..2022647 100644
--- a/kernel/Dictionary.st
+++ b/kernel/Dictionary.st
@@ -435,7 +435,6 @@ certain special cases.'>
<category: 'printing'>
| class instVars i |
- self beConsistent.
class := self class.
instVars := class allInstVarNames.
aStream nextPutAll: 'An instance of '.
@@ -568,8 +567,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 +582,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/LookupTable.st b/kernel/LookupTable.st
index fdcb111..d1444e0 100644
--- a/kernel/LookupTable.st
+++ b/kernel/LookupTable.st
@@ -153,7 +153,6 @@ equality comparison message #= to determine equivalence of indices.'>
"Pass each key in the LookupTable to aBlock."
<category: 'enumerating'>
- self beConsistent.
1 to: self primSize
do: [:i | (self primAt: i) notNil ifTrue: [aBlock value: (self primAt: i)]]
]
@@ -162,7 +161,6 @@ equality comparison message #= to determine equivalence of indices.'>
"Pass each value in the LookupTable to aBlock."
<category: 'enumerating'>
- self beConsistent.
1 to: self primSize
do: [:i | (self primAt: i) notNil ifTrue: [aBlock value: (self valueAt: i)]]
]
@@ -326,8 +324,6 @@ equality comparison 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 hash scramble bitAnd: (size := self primSize) - 1) + 1.
@@ -343,8 +339,6 @@ equality comparison 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 hash scramble bitAnd: (size := self primSize) - 1) + 1.
diff --git a/kernel/OrderColl.st b/kernel/OrderColl.st
index 7d15dd4..5c94b99 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"
@@ -310,7 +304,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"
@@ -370,7 +363,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/SeqCollect.st b/kernel/SeqCollect.st
index f810fa1..d79ddaa 100644
--- a/kernel/SeqCollect.st
+++ b/kernel/SeqCollect.st
@@ -59,7 +59,6 @@ some access and manipulation methods.'>
<category: 'testing'>
| instVars object output |
- self beConsistent.
aStream
nextPutAll: 'An instance of ';
print: self class;
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/SortCollect.st b/kernel/SortCollect.st
index fb5c13e..14eb5a8 100644
--- a/kernel/SortCollect.st
+++ b/kernel/SortCollect.st
@@ -113,6 +113,22 @@ above criteria -- actually any object which responds to #value:value:.'>
self shouldNotImplement
]
+ do: aBlock [
+ "Evaluate aBlock for all the elements in the collection"
+
+ <category: 'enumerating'>
+ self beConsistent.
+ super do: aBlock
+ ]
+
+ first [
+ "Answer the first item of the receiver"
+
+ <category: 'accessing'>
+ self beConsistent.
+ ^ super first
+ ]
+
last [
"Answer the last item of the receiver"
@@ -124,6 +140,31 @@ above criteria -- actually any object which responds to #value:value:.'>
ifFalse: [self basicAt: firstIndex]
]
+ at: anIndex [
+ "Answer the anIndex-th item of the receiver"
+
+ <category: 'accessing'>
+ self beConsistent.
+ ^ super at: anIndex
+ ]
+
+ at: anIndex put: anObject [
+ "Store anObject at the anIndex-th item of the receiver, answer anObject"
+
+ <category: 'accessing'>
+ self beConsistent.
+ super at: anIndex put: anObject
+ ]
+
+ 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"
@@ -282,6 +323,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
@@ -730,5 +772,13 @@ above criteria -- actually any object which responds to #value:value:.'>
ifFalse: [high := mid - 1]].
^low
]
+
+ examineOn: aStream [
+ "Print all the instance variables and objects in the receiver on aStream"
+
+ <category: 'printing'>
+ self beConsistent.
+ super examineOn: aStream
+ ]
]
diff --git a/kernel/WeakObjects.st b/kernel/WeakObjects.st
index 25cf7f9..8342914 100644
--- a/kernel/WeakObjects.st
+++ b/kernel/WeakObjects.st
@@ -296,8 +296,6 @@ one of them, I swiftly remove all.'>
<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.
@@ -313,8 +311,6 @@ one of them, I swiftly remove all.'>
<category: 'private'>
| 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.
@@ -427,6 +423,22 @@ for the garbage collected values'>
^true
]
+ keysDo: aBlock [
+ "Pass each key in the LookupTable to aBlock."
+
+ <category: 'enumerating'>
+ self beConsistent.
+ super keysDo: aBlock
+ ]
+
+ do: aBlock [
+ "Pass each value in the LookupTable to aBlock."
+
+ <category: 'enumerating'>
+ self beConsistent.
+ super do: aBlock
+ ]
+
beConsistent [
"Private - Clean the dictionary of key->(finalized value) pairs"
@@ -506,6 +518,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
+ ]
+
+ examineOn: aStream [
+ "Print all the instance variables and objects in the receiver on aStream"
+
+ <category: 'printing'>
+ self beConsistent.
+ super examineOn: aStream
+ ]
]
@@ -533,8 +572,6 @@ encounter one of them, I swiftly remove all the garbage collected keys'>
<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.
@@ -578,8 +615,6 @@ for the garbage collected keys'>
<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/packages/stinst/parser/ParseTreeSearcher.st b/packages/stinst/parser/ParseTreeSearcher.st
index cad2115..84395fa 100644
--- a/packages/stinst/parser/ParseTreeSearcher.st
+++ b/packages/stinst/parser/ParseTreeSearcher.st
@@ -340,7 +340,6 @@ LookupTable subclass: RBSmallDictionary [
<category: 'private'>
| element |
- self beConsistent.
1 to: self size
do:
[:i |
diff --git a/packages/stinst/parser/STSymTable.st b/packages/stinst/parser/STSymTable.st
index de97aa7..6708716 100644
--- a/packages/stinst/parser/STSymTable.st
+++ b/packages/stinst/parser/STSymTable.st
@@ -128,8 +128,6 @@ comparison message #literalEquals: to determine equivalence of objects.'>
<category: 'private methods'>
| index size element |
- self beConsistent.
-
"Sorry for the lack of readability, but I want speed... :-)"
index := (anObject literalHash scramble
bitAnd: (size := self primSize) - 1) + 1.
_______________________________________________
help-smalltalk mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-smalltalk