Skip to content

Commit

Permalink
Use StructArrays in EDStore
Browse files Browse the repository at this point in the history
  • Loading branch information
peremato committed Sep 27, 2024
1 parent 974852c commit 39873ed
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ julia = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
3 changes: 3 additions & 0 deletions docs/src/release_notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# Release Notes

## 0.4.x
- Use StructArrays also for EDStore when building the model directly.


## 0.4.0
### New Functionality
Expand Down
2 changes: 1 addition & 1 deletion src/Components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ end
Base.propertynames(oid::ObjectID) = tuple(fieldnames(ObjectID)...,:object)
function register(p::ED) where ED
collid = collectionID(ED)
store::Vector{ED} = EDStore_objects(ED, collid)
store = EDStore_objects(ED, collid)
!iszero(p.index) && error("Registering an already registered MCParticle $p")
last = lastindex(store)
p = @set p.index = ObjectID{ED}(last, collid)
Expand Down
8 changes: 5 additions & 3 deletions src/EDStore.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using StructArrays

export EDStore, getEDStore, initEDStore, assignEDStore, emptyEDStore, assignEDStore_relations, assignEDStore_vmembers

mutable struct EDStore{ED <: POD}
Expand All @@ -8,13 +10,13 @@ mutable struct EDStore{ED <: POD}
end

function initialize!(store::EDStore{ED}) where ED <: POD
store.objects = ED[]
store.objects = StructArray(ED[])
store.relations = Tuple(ObjectID{eltype(R)}[] for R in relations(ED))
store.vmembers = Tuple(ObjectID{eltype(R)}[] for R in vmembers(ED))
end

function Base.empty!(store::EDStore{ED}) where ED <: POD
store.objects isa Vector && empty!(store.objects)
store.objects isa StructArray & empty!(store.objects)
for (i,R) in enumerate(relations(ED))
store.relations[i] isa Vector && empty!(store.relations[i])
end
Expand Down Expand Up @@ -82,7 +84,7 @@ end
function EDStore_objects(::Type{ED}, collid::UInt32=0x00000000) where ED
store = getEDStore(ED, collid)
if !isdefined(store, :objects)
store.objects = ED[]
store.objects = StructArray(ED[])
end
store.objects
end
Expand Down

0 comments on commit 39873ed

Please sign in to comment.