[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-smalltalk] [PATCH] a couple of collection speedups
From: |
Paolo Bonzini |
Subject: |
[Help-smalltalk] [PATCH] a couple of collection speedups |
Date: |
Thu, 22 May 2008 09:54:27 +0200 |
User-agent: |
Thunderbird 2.0.0.14 (Macintosh/20080421) |
Here they are.
Paolo
diff --git a/ChangeLog b/ChangeLog
index 79b78ca..f29b722 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-05-22 Paolo Bonzini <address@hidden>
+
+ * kernel/OrderColl.st: Override #first and #last for speed.
+ * kernel/StreamOps.st: Avoid repeatedly colling #first.
+ * kernel/SeqCollect.st: Use #replaceFrom:to:with:startingAt: when doing
+ #replaceFrom:to:with: with a sequenceable collection argument.
+
2008-05-21 Paolo Bonzini <address@hidden>
* kernel/CCallback.st: New.
diff --git a/kernel/OrderColl.st b/kernel/OrderColl.st
index cc0ed2b..66bd8b6 100644
--- a/kernel/OrderColl.st
+++ b/kernel/OrderColl.st
@@ -56,6 +56,26 @@ on content (such as add:after:)'>
^self new: 16
]
+ first [
+ "Answer the first item of the receiver"
+
+ <category: 'accessing'>
+ self beConsistent.
+ ^lastIndex >= firstIndex
+ ifTrue: [self basicAt: firstIndex]
+ ifFalse: [SystemExceptions.IndexOutOfRange signalOn: self
withIndex: 1]
+ ]
+
+ last [
+ "Answer the last item of the receiver"
+
+ <category: 'accessing'>
+ self beConsistent.
+ ^lastIndex >= firstIndex
+ ifTrue: [self basicAt: lastIndex]
+ ifFalse: [SystemExceptions.IndexOutOfRange signalOn: self
withIndex: 0]
+ ]
+
at: anIndex [
"Answer the anIndex-th item of the receiver"
@@ -63,9 +83,9 @@ on content (such as add:after:)'>
| index |
self beConsistent.
index := anIndex + firstIndex - 1.
- (index >= firstIndex and: [index <= lastIndex])
- ifTrue: [^self basicAt: index]
- ifFalse: [^SystemExceptions.IndexOutOfRange signalOn: self
withIndex: anIndex]
+ ^(index >= firstIndex and: [index <= lastIndex])
+ ifTrue: [self basicAt: index]
+ ifFalse: [SystemExceptions.IndexOutOfRange signalOn: self
withIndex: anIndex]
]
at: anIndex put: anObject [
diff --git a/kernel/SeqCollect.st b/kernel/SeqCollect.st
index 66b1aeb..1ee37f7 100644
--- a/kernel/SeqCollect.st
+++ b/kernel/SeqCollect.st
@@ -550,6 +550,9 @@ some access and manipulation methods.'>
<category: 'replacing items'>
| i |
+ replacementCollection isSequenceable ifTrue: [
+ ^self replaceFrom: start to: stop with: replacementCollection
startingAt: 1 ].
+
i := start - 1.
stop - i = replacementCollection size
ifFalse: [^SystemExceptions.InvalidSize signalOn:
replacementCollection size].
diff --git a/kernel/StreamOps.st b/kernel/StreamOps.st
index 0dd11e1..01744b4 100644
--- a/kernel/StreamOps.st
+++ b/kernel/StreamOps.st
@@ -77,15 +77,21 @@ Stream subclass: ConcatenatedStream [
streams := streams copy
]
- atEnd [
+ stream [
<category: 'all'>
- [streams first atEnd] whileTrue:
- [streams size = 1 ifTrue: [^true].
+ | s |
+ [(s := streams first) atEnd] whileTrue:
+ [streams size = 1 ifTrue: [^nil].
lastStart := startPos.
startPos := startPos + curPos.
curPos := 0.
last := streams removeFirst].
- ^false
+ ^s
+ ]
+
+ atEnd [
+ <category: 'all'>
+ ^self stream isNil
]
name [
@@ -96,8 +102,10 @@ Stream subclass: ConcatenatedStream [
next [
<category: 'all'>
- self atEnd ifFalse: [curPos := curPos + 1].
- ^streams first next
+ | s |
+ ^(s := self stream) isNil
+ ifTrue: [self pastEnd]
+ ifFalse: [curPos := curPos + 1. s next]
]
pastEnd [
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Help-smalltalk] [PATCH] a couple of collection speedups,
Paolo Bonzini <=