Skip to content

Commit 9062d32

Browse files
committed
Use setdefault for ctx caches
1 parent c454681 commit 9062d32

3 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/flint/types/nmod.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ cdef class nmod_ctx:
6262
"""Retrieve an nmod context from the cache or create a new one."""
6363
ctx = _nmod_ctx_cache.get(mod)
6464
if ctx is None:
65-
_nmod_ctx_cache[mod] = ctx = nmod_ctx._new_ctx(mod)
65+
ctx = _nmod_ctx_cache.setdefault(mod, nmod_ctx._new_ctx(mod))
6666
return ctx
6767

6868
@staticmethod

src/flint/types/nmod_mat.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ cdef class nmod_mat_ctx:
9494
"""Retrieve an nmod_mat context from the cache or create a new one."""
9595
ctx = _nmod_mat_ctx_cache.get(mod)
9696
if ctx is None:
97-
_nmod_mat_ctx_cache[mod] = ctx = nmod_mat_ctx._new_ctx(mod)
97+
ctx = _nmod_mat_ctx_cache.setdefault(mod, nmod_mat_ctx._new_ctx(mod))
9898
return ctx
9999

100100
@staticmethod

src/flint/types/nmod_poly.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ cdef class nmod_poly_ctx:
4949
"""Retrieve an nmod_poly context from the cache or create a new one."""
5050
ctx = _nmod_poly_ctx_cache.get(mod)
5151
if ctx is None:
52-
_nmod_poly_ctx_cache[mod] = ctx = nmod_poly_ctx._new_ctx(mod)
52+
ctx = _nmod_poly_ctx_cache.setdefault(mod, nmod_poly_ctx._new_ctx(mod))
5353
return ctx
5454

5555
@staticmethod

0 commit comments

Comments
 (0)