[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-smalltalk] [PATCH] kernel: Speed up MethodDictionary>>#select:
From: |
Holger Hans Peter Freyther |
Subject: |
[Help-smalltalk] [PATCH] kernel: Speed up MethodDictionary>>#select: |
Date: |
Sun, 19 Jan 2014 17:14:36 +0100 |
From: Gwenaƫl Casaccio <address@hidden>
The default >>#select: implementation will call Behavior>>#flushCache:
for every CompiledMethod that is inserted into the new Dictionary.
Avoid this by creating a dedicated >>#select: implementation that avoid
the cache flush.
2014-01-19 Gwenael Casaccio <address@hidden>
* kernel/MethodDict.st: Introduce >>#select: and
>>#dangerouslyAt:put:.
---
ChangeLog | 5 +++++
kernel/MethodDict.st | 31 ++++++++++++++++++++++++++++++-
2 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index ea47151..46a0bc5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-01-19 Gwenael Casaccio <address@hidden>
+
+ * kernel/MethodDict.st: Introduce >>#select: and
+ >>#dangerouslyAt:put:.
+
2013-12-14 Holger Hans Peter Freyther <address@hidden>
* configure.ac: Check for environ with AC_CHECK_DECLS.
diff --git a/kernel/MethodDict.st b/kernel/MethodDict.st
index 155a8ac..cd02090 100644
--- a/kernel/MethodDict.st
+++ b/kernel/MethodDict.st
@@ -7,7 +7,7 @@
"======================================================================
|
-| Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+| Copyright 1999, 2000, 2001, 2002, 2014 Free Software Foundation, Inc.
| Written by Paolo Bonzini.
|
| This file is part of the GNU Smalltalk class library.
@@ -119,6 +119,35 @@ interpreter.'>
self mutex critical: [ self growBy: 0 ]
]
+ select: aBlock [
+ "Answer a new dictionary containing the key/value pairs for which
aBlock
+ returns true. aBlock only receives the value part of the pairs."
+
+ <category: 'dictionary enumerating'>
+ | newDict |
+ newDict := self copyEmpty: self capacity.
+ self
+ associationsDo: [:assoc |
+ (aBlock value: assoc value)
+ ifTrue: [newDict dangerouslyAt: assoc key put: assoc
value]].
+ ^newDict
+ ]
+
+ dangerouslyAt: aKey put: aValue [
+ <category: 'private methods'>
+
+ | index |
+ index := self findIndex: aKey.
+ (self primAt: index) isNil
+ ifTrue: [
+ self incrementTally
+ ifTrue: [ index := self findIndex: aKey ].
+ self primAt: index put: aKey]
+ ifFalse: [ (self valueAt: index) discardTranslation ].
+ self valueAt: index put: aValue.
+ ^ aValue
+ ]
+
dangerouslyRemove: anAssociation [
"This is not really dangerous. But if normal removal
were done WHILE a MethodDictionary were being used, the
--
1.8.5.2
- [Help-smalltalk] [PATCH] kernel: Speed up MethodDictionary>>#select:,
Holger Hans Peter Freyther <=