Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Fame-Core/FMMultivalueLink.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,11 @@ FMMultivalueLink >> uncheckUnsafeAdd: element [

{ #category : 'private' }
FMMultivalueLink >> unsafeAdd: element [
"The cost of this #includes can be pretty high so there is a way to disable it when we know there will be no duplicates. Check the class comment of the dynamic variable."

(self includes: element) ifFalse: [ super addLast: element ]
FMShouldCheckForDuplicatedEntitiesInMultivalueLinks value
ifTrue: [ (self includes: element) ifFalse: [ self uncheckUnsafeAdd: element ] ]
ifFalse: [ self uncheckUnsafeAdd: element ]
]

{ #category : 'private' }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"
## Description

I am a dynamic variable used by implementations of multivalue links to know if we should check for duplicated entities in multivalue links.

For example, when importing a json, we are sure we will never add two times the same entity to a multivalue link.

I exist for performance reason because the cost of checking for duplicated entities is high.

By default I will enable the check.

## Usage

```smalltalk
FMShouldCheckForDuplicatedEntitiesInMultivalueLinks value: false during: [ self importModel ]
```
"
Class {
#name : 'FMShouldCheckForDuplicatedEntitiesInMultivalueLinks',
#superclass : 'DynamicVariable',
#category : 'Fame-Core-Utilities',
#package : 'Fame-Core',
#tag : 'Utilities'
}

{ #category : 'accessing' }
FMShouldCheckForDuplicatedEntitiesInMultivalueLinks >> default [

^ true
]
5 changes: 4 additions & 1 deletion src/Fame-Core/FMSlotMultivalueLink.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ FMSlotMultivalueLink >> uncheckUnsafeAdd: element [

{ #category : 'private' }
FMSlotMultivalueLink >> unsafeAdd: element [
"The cost of this #includes can be pretty high so there is a way to disable it when we know there will be no duplicates. Check the class comment of the dynamic variable."

(self includes: element) ifFalse: [ super addLast: element ]
FMShouldCheckForDuplicatedEntitiesInMultivalueLinks value
ifTrue: [ (self includes: element) ifFalse: [ self uncheckUnsafeAdd: element ] ]
ifFalse: [ self uncheckUnsafeAdd: element ]
]

{ #category : 'private' }
Expand Down
7 changes: 5 additions & 2 deletions src/Fame-ImportExport/FMMSEParser.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,11 @@ FMMSEParser >> backtrack: integer [

{ #category : 'running' }
FMMSEParser >> basicRun [
self Document.
self atEnd ifFalse: [ ^ self syntaxError ]
"During the parsing of MSE files we know there will be no duplicates in collections so we can disable the check."

FMShouldCheckForDuplicatedEntitiesInMultivalueLinks value: false during: [
self Document.
self atEnd ifFalse: [ ^ self syntaxError ] ]
]

{ #category : 'accessing' }
Expand Down