Skip to content

Commit

Permalink
Use GFFieldID for caching GF(p)
Browse files Browse the repository at this point in the history
Builds upon #1659 to provide thread-safety by default.
  • Loading branch information
sumiya11 committed Apr 6, 2024
1 parent 17e182a commit f11bb81
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/julia/JuliaTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,13 @@ mutable struct GFField{T <: Integer} <: FinField
p::T

function GFField{T}(p::T; cached::Bool = true) where T <: Integer
if cached && haskey(GFFieldID, (T, p))
z = GFFieldID[T, p]::GFField{T}
else
z = new{T}(p)
if cached
GFFieldID[T, p] = z
end
end
return z
return get_cached!(GFFieldID, (T, p), cached) do
new{T}(p)
end::GFField{T}
end
end

const GFFieldID = Dict{Tuple{DataType, Integer}, Field}()
const GFFieldID = CacheDictType{Tuple{DataType, Integer}, Field}()

struct GFElem{T <: Integer} <: FinFieldElem
d::T
Expand Down

0 comments on commit f11bb81

Please sign in to comment.