Skip to content

Commit

Permalink
Add some type assertions (#831)
Browse files Browse the repository at this point in the history
... to improve type stability in some situations.

Also remove two redundant dict writes: get! already stores these
  • Loading branch information
fingolfin authored Sep 19, 2024
1 parent eb1d59d commit 93bad85
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/ideal/IdealTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mutable struct IdealSet{T <: AbstractAlgebra.NCRingElem} <: Set
function IdealSet{T}(R::PolyRing) where T
return get!(IdealSetID, R) do
new(R)
end
end::IdealSet{T}
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/matrix/MatrixTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mutable struct matrix_space{T <: Nemo.RingElem} <: Set
function matrix_space{T}(R::PolyRing, r::Int, c::Int) where T
return get!(MatrixSpaceID, (R, r, c)) do
new{T}(R, r, c)
end
end::matrix_space{T}
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/module/ModuleTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mutable struct FreeMod{T <: Nemo.RingElem} <: Module{T}
function FreeMod{T}(R::PolyRing, r::Int) where T
return get!(FreeModID, (R, r)) do
new(R, r)
end
end::FreeMod{T}
end
end

Expand Down Expand Up @@ -63,7 +63,7 @@ mutable struct ModuleClass{T <: Nemo.RingElem} <: Set
function ModuleClass{T}(R::PolyRing) where T
return get!(ModuleClassID, R) do
new(R)
end
end::ModuleClass{T}
end
end

Expand Down
6 changes: 2 additions & 4 deletions src/number/NumberTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ mutable struct Integers <: Ring
return get!(IntegersID, :ZZ) do
ptr = libSingular.nInitChar(libSingular.n_Z, Ptr{Nothing}(0))
d = new(ptr, 0)
IntegersID[:ZZ] = d
finalizer(_Ring_finalizer, d)
return d
end
end::Integers
end
end

Expand Down Expand Up @@ -78,10 +77,9 @@ mutable struct Rationals <: Field
return get!(RationalsID, :QQ) do
ptr = libSingular.nInitChar(libSingular.n_Q, Ptr{Nothing}(0))
d = new(ptr, 0)
RationalsID[:QQ] = d
finalizer(_Ring_finalizer, d)
return d
end
end::Rationals
end
end

Expand Down

0 comments on commit 93bad85

Please sign in to comment.