Skip to content

Commit

Permalink
dc: perf improvements, various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tom95 committed Oct 11, 2023
1 parent 17116ff commit 06feaec
Show file tree
Hide file tree
Showing 15 changed files with 238 additions and 102 deletions.
13 changes: 13 additions & 0 deletions packages/DomainCode-Core/DCQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,26 @@ DCQuery class >> removeProperty: anObject from: aDomainObject [
ifPresent: [:properties | properties remove: aDomainObject]
]

{ #category : #'as yet unclassified' }
DCQuery class >> script: aCollection allDeep: anotherCollection [

^ Array streamContents: [:s | anotherCollection allChildrenDo: [:obj | (self script: aCollection with: obj) ifNotNil: [:res | s nextPut: res]]]
]

{ #category : #'as yet unclassified' }
DCQuery class >> script: aCollection first: anotherCollection [

anotherCollection do: [:obj | (self script: aCollection with: obj) ifNotNil: [:res | ^ res]].
^ nil
]

{ #category : #'as yet unclassified' }
DCQuery class >> script: aCollection firstDeep: anotherCollection [

anotherCollection allChildrenDo: [:obj | (self script: aCollection with: obj) ifNotNil: [:res | ^ res]].
^ nil
]

{ #category : #'as yet unclassified' }
DCQuery class >> script: aCollection with: anObject [

Expand Down
26 changes: 24 additions & 2 deletions packages/DomainCode-Core/Morph.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Morph >> allChildrenBreadthFirstDo: aBlock [
{ #category : #'*DomainCode-Core' }
Morph >> allChildrenDo: aBlock [

self children do: [:c | c allChildrenDo: aBlock].
self childrenDo: [:c | c allChildrenDo: aBlock].
aBlock value: self
]

Expand All @@ -37,12 +37,33 @@ Morph >> allDomainBlocksWithDepthDo: aBlock leafDo: anotherBlock depth: aNumber
anotherBlock value: self value: aNumber
]

{ #category : #'*DomainCode-Core' }
Morph >> childCount [

| i |
i := 0.
self childrenDo: [:c | i := i + 1].
^ i
]

{ #category : #'*DomainCode-Core' }
Morph >> children [

^ submorphs
]

{ #category : #'*DomainCode-Core' }
Morph >> childrenDo: aBlock [

submorphs do: aBlock
]

{ #category : #'*DomainCode-Core' }
Morph >> childrenSelect: aBlock [

^ Array streamContents: [:s | self childrenDo: [:c | (aBlock value: c) ifTrue: [s nextPut: c]]]
]

{ #category : #'*DomainCode-Core' }
Morph >> firstDeepChildNode [

Expand All @@ -55,7 +76,8 @@ Morph >> firstDeepChildNode [
{ #category : #'*DomainCode-Core' }
Morph >> hasChildren [

^ self children notEmpty
self childrenDo: [:c | ^ true].
^ false
]

{ #category : #'*DomainCode-Core' }
Expand Down
8 changes: 4 additions & 4 deletions packages/DomainCode-Diff/DCChawatheScriptGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ Class {
DCChawatheScriptGenerator >> alignChildrenSrc: w dest: x srcInOrder: srcInOrder destInOrder: destInOrder in: aMapping [

| s1 s2 lcs |
w children do: [:c | srcInOrder remove: c ifAbsent: []].
x children do: [:c | destInOrder remove: c ifAbsent: []].
w childrenDo: [:c | srcInOrder remove: c ifAbsent: []].
x childrenDo: [:c | destInOrder remove: c ifAbsent: []].

s1 := w children select: [:c | (aMapping isSrcMapped: c) and: [x children includes: (aMapping destForSrc: c)]].
s2 := x children select: [:c | (aMapping isDestMapped: c) and: [w children includes: (aMapping srcForDest: c)]].
s1 := w childrenSelect: [:c | (aMapping isSrcMapped: c) and: [x children includes: (aMapping destForSrc: c)]].
s2 := x childrenSelect: [:c | (aMapping isDestMapped: c) and: [w children includes: (aMapping srcForDest: c)]].

lcs := self lcsWith: s1 and: s2 in: aMapping.
lcs do: [:mapping |
Expand Down
18 changes: 11 additions & 7 deletions packages/DomainCode-Diff/DCMappingComparator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Class {
'destAncestors',
'rootSrc',
'rootDest',
'absolutePositions'
'absolutePositions',
'indicesInParents'
],
#category : #'DomainCode-Diff'
}
Expand Down Expand Up @@ -102,17 +103,17 @@ DCMappingComparator >> longestCommonSubsequenceWith: aCollection and: anotherCol
1 to: aCollection size do: [:i |
1 to: anotherCollection size do: [:j |
(aCollection at: i) type = (anotherCollection at: j) type
ifTrue: [lengths at: i + 1 at: j + 1 put: (lengths at: i at: j)]
ifFalse: [lengths at: i + 1 at: j + 1 put: ((lengths at: i + 1 at: j) max: (lengths at: i at: j + 1))]]].
ifTrue: [lengths atFast: i + 1 at: j + 1 put: (lengths atFast: i at: j)]
ifFalse: [lengths atFast: i + 1 at: j + 1 put: ((lengths atFast: i + 1 at: j) max: (lengths at: i at: j + 1))]]].

indices := OrderedCollection new.
x := aCollection size + 1.
y := anotherCollection size + 1.
[x > 1 and: [y > 1]] whileTrue: [
(lengths at: x at: y) = (lengths at: x - 1 at: y)
(lengths atFast: x at: y) = (lengths atFast: x - 1 at: y)
ifTrue: [x := x - 1]
ifFalse: [
(lengths at: x at: y) = (lengths at: x at: y - 1)
(lengths atFast: x at: y) = (lengths atFast: x at: y - 1)
ifTrue: [y := y - 1]
ifFalse: [
indices add: {x - 1. y - 1}.
Expand Down Expand Up @@ -193,9 +194,12 @@ DCMappingComparator >> similarityPositionInParentsCompare: aMapping with: anothe
indices add: current siblingIndex.
current := current parent].
indices].

indicesInParents ifNil: [indicesInParents := Dictionary new].

distance := [:mapping | | indicesVec1 indicesVec2 sum |
indicesVec1 := indicesInOwnerSubmorphs value: mapping first.
indicesVec2 := indicesInOwnerSubmorphs value: mapping second.
indicesVec1 := indicesInParents at: mapping first ifAbsentPut: [indicesInOwnerSubmorphs value: mapping first].
indicesVec2 := indicesInParents at: mapping second ifAbsentPut: [indicesInOwnerSubmorphs value: mapping second].
sum := 0.0.
1
to: (indicesVec1 size min: indicesVec2 size)
Expand Down
2 changes: 2 additions & 0 deletions packages/DomainCode-Diff/DCMatcher.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ DCMatcher >> matchFrom: src to: dest [
{ #category : #'as yet unclassified' }
DCMatcher >> performEditsIn: aDest to: aSrc [

aSrc allChildrenDo: [:m | m clearDiffCache].

DCChawatheScriptGenerator new
generateFrom: aSrc
to: aDest
Expand Down
Loading

0 comments on commit 06feaec

Please sign in to comment.