refactoring
authorClaus Gittinger <cg@exept.de>
Sat, 08 Sep 2001 21:18:00 +0200
changeset 6013 67fe7838f006
parent 6012 21eebe6e6997
child 6014 14acbd7c25d4
refactoring
CompiledCode.st
--- a/CompiledCode.st	Fri Sep 07 21:29:54 2001 +0200
+++ b/CompiledCode.st	Sat Sep 08 21:18:00 2001 +0200
@@ -390,7 +390,7 @@
 !
 
 literals
-    "return the literal array"
+    "return the literals as an array"
 
     |lits numLits "{ Class: SmallInteger }"|
 
@@ -427,29 +427,14 @@
 
 literalsDetect:aBlock ifNone:exceptionBlock
     "execute a one arg block for each of our literals.
-     return the first literal for which aBlock returns true"
-
-    |lits theLit numLits "{Class: SmallInteger }"|
+     return the first literal for which aBlock returns true,
+     or the value from exceptionBlock, if either no literals or
+     none satisfied the block"
 
-    numLits := self size.
-    numLits > 0 ifTrue:[
-        numLits == 1 ifTrue:[
-            lits := self at:1.
-            numLits := lits size.
-        ] ifFalse:[
-            lits := self.
-            "there may be a dummy (nil) literal to make the size > 1"
-            (self at:2) isNil ifTrue:[
-                numLits := 1.
-            ].
-        ].
-
-        1 to:numLits do:[:i |
-            theLit := lits at:i.
-            (aBlock value:theLit) ifTrue:[
-                ^ theLit.
-            ].
-        ].
+    self literalsDo:[:eachLiteral |
+        (aBlock value:eachLiteral) ifTrue:[
+            ^ eachLiteral
+        ]
     ].
     ^ exceptionBlock value.
 
@@ -1673,6 +1658,6 @@
 !CompiledCode class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/CompiledCode.st,v 1.84 2000-12-13 13:14:27 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CompiledCode.st,v 1.85 2001-09-08 19:18:00 cg Exp $'
 ! !
 CompiledCode initialize!