Skip to content

Commit

Permalink
RelationSlot was compiling a reflective write. But we can do better;
Browse files Browse the repository at this point in the history
- refactor write: to:  so we do most of the stuff in another method
- implement emitStore: to call that method and use bytecodes to acces ivars

This PR was done to speed up Moose which uses RelationSlots a lot.
  • Loading branch information
MarcusDenker committed Jul 1, 2020
1 parent bf72325 commit b869f83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
10 changes: 7 additions & 3 deletions src/Slot-Examples/RelationSlot.class.st
Expand Up @@ -71,17 +71,21 @@ RelationSlot >> checkValue: aValue [

{ #category : #'code generation' }
RelationSlot >> emitStore: aMethodBuilder [
"copy of #emitStore from Slot as my superclass has overriden it"
"This bytecode does the following:
self updateOld: (self read: anObject) new: newValue in: anObject.
super write: newValue to: anObject
"
| tempName |
tempName := '0slotTempForStackManipulation'.
aMethodBuilder
addTemp: tempName;
storeTemp: tempName;
popTop;
pushReceiver;
pushLiteralVariable: (AdditionalBinding key: #slot value: self);
pushInstVar: index;
pushTemp: tempName;
send: #writeSlot:value:
send: #updateOld:new:in:;
storeInstVar: index
]

{ #category : #testing }
Expand Down
22 changes: 11 additions & 11 deletions src/Slot-Examples/ToOneRelationSlot.class.st
Expand Up @@ -13,21 +13,21 @@ ToOneRelationSlot >> isToOneSlot [
^true
]

{ #category : #'meta-object-protocol' }
ToOneRelationSlot >> write: newValue to: anObject [

| oldValue |
{ #category : #internal }
ToOneRelationSlot >> updateOld: oldValue new: newValue in: anObject [

oldValue := self read: anObject.
newValue notNil
ifTrue: [ self checkValue: newValue ].
self hasInverse
ifTrue: [
oldValue notNil
self hasInverse ifFalse: [^ self ].
oldValue notNil
ifTrue: [ self removeAssociationFrom: anObject to: oldValue ].
newValue notNil
ifTrue: [ self addAssociationFrom: anObject to: newValue ] ].

newValue notNil
ifTrue: [ self addAssociationFrom: anObject to: newValue ]
]

{ #category : #'meta-object-protocol' }
ToOneRelationSlot >> write: newValue to: anObject [
self updateOld: (self read: anObject) new: newValue in: anObject.
super write: newValue to: anObject
]

Expand Down

0 comments on commit b869f83

Please sign in to comment.