From 3bcb77002484ca36d5a5f22ff790e454b0dc780b Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 21 Sep 2024 11:08:51 +0200 Subject: [PATCH] Turn FinGenAbGroupElem into a non-mutable struct This reduce allocations and increases speed of code using these elements. --- src/GrpAb/Elem.jl | 10 ---------- src/HeckeTypes.jl | 9 +++++++-- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/GrpAb/Elem.jl b/src/GrpAb/Elem.jl index ec0d97fe54..402921cc2e 100644 --- a/src/GrpAb/Elem.jl +++ b/src/GrpAb/Elem.jl @@ -44,16 +44,6 @@ end # ################################################################################ -# This destroy's the input. If you don't want this, use A(::ZZMatrix) - -function FinGenAbGroupElem(A::FinGenAbGroup, a::ZZMatrix) - assure_reduced!(A, a) - z = FinGenAbGroupElem() - z.parent = A - z.coeff = a - return z -end - function reduce_mod_snf!(a::ZZMatrix, v::Vector{ZZRingElem}) GC.@preserve a begin for i = 1:length(v) diff --git a/src/HeckeTypes.jl b/src/HeckeTypes.jl index c0446ff4c9..36c2dec7fa 100644 --- a/src/HeckeTypes.jl +++ b/src/HeckeTypes.jl @@ -1828,11 +1828,16 @@ abstract type GrpAbElem <: AbstractAlgebra.AdditiveGroupElem end end -mutable struct FinGenAbGroupElem <: GrpAbElem +struct FinGenAbGroupElem <: GrpAbElem parent::FinGenAbGroup coeff::ZZMatrix - FinGenAbGroupElem() = new() + # This destroy's the input. If you don't want this, use A(::ZZMatrix) + function FinGenAbGroupElem(A::FinGenAbGroup, a::ZZMatrix) + assure_reduced!(A, a) + return new(A, a) + end + end ################################################################################